module Demiurge::DSL

This module contains the Builder classes that parse the World File DSL.

@since 0.0.1

Public Class Methods

engine_from_dsl_files(*filenames) click to toggle source

This is a primary method for creating a new Demiurge Engine. It should be passed a list of filenames to load World File DSL from. It will return a fully-configured Engine which has called finished_init. If the Engine should load from an existing state-dump, that can be accomplished via load_state_from_dump.

@see file:RELOADING.md @see Demiurge::Engine#load_state_from_dump @see Demiurge::Engine#reload_from_dsl_files @param filenames [Array<String>] An array of filenames, suitable for calling File.read on @return [Demiurge::Engine] A configured Engine @since 0.0.1

# File lib/demiurge/dsl.rb, line 171
def self.engine_from_dsl_files(*filenames)
  filename_string_pairs = filenames.map { |fn| [fn, File.read(fn)] }
  engine_from_dsl_text(*filename_string_pairs)
end
engine_from_dsl_text(*specs) click to toggle source

This method takes either strings containing World File DSL text, or name/string pairs. If a pair is supplied, the name gives the origin of the text for error messages.

@see file:RELOADING.md @see Demiurge::Engine#load_state_from_dump @see Demiurge::Engine#reload_from_dsl_text @param specs [Array<String>, Array<Array<String>>] Either an array of chunks of DSL text, or an Array of two-element Arrays. Each two-element Array is a String name followed by a String of DSL text @return [Demiurge::Engine] A configured Engine @since 0.0.1

# File lib/demiurge/dsl.rb, line 186
def self.engine_from_dsl_text(*specs)
  builder = Demiurge::DSL::TopLevelBuilder.new

  specs.each do |spec|
    if spec.is_a?(String)
      builder.instance_eval spec
    elsif spec.is_a?(Array)
      if spec.size != 2
        raise "Not sure what to do with a #{spec.size}-elt array, normally this is a filename/string pair!"
      end
      builder.instance_eval spec[1], spec[0]
    else
      raise "Not sure what to do in engine_from_dsl_text with a #{spec.class}!"
    end
  end

  builder.built_engine
end