class DSLCompanion::Interpreter
Constants
- DEFAULT_EXEC_MODE
Attributes
current_context[R]
exec_mode[R]
logger[W]
Public Class Methods
new(exec_mode=DEFAULT_EXEC_MODE)
click to toggle source
# File lib/dsl_companion/interpreter.rb, line 12 def initialize(exec_mode=DEFAULT_EXEC_MODE) @interpreter = self self.exec_mode = exec_mode @current_context = self end
run(file=nil, exec_mode=DEFAULT_EXEC_MODE, &block)
click to toggle source
# File lib/dsl_companion/interpreter.rb, line 32 def self.run(file=nil, exec_mode=DEFAULT_EXEC_MODE, &block) new(exec_mode).run file, &block end
Public Instance Methods
add_feature(mod)
click to toggle source
# File lib/dsl_companion/interpreter.rb, line 55 def add_feature(mod) self.meta_eval do include mod end end
exec_mode=(mode)
click to toggle source
# File lib/dsl_companion/interpreter.rb, line 37 def exec_mode=(mode) if [:strict, true].include? mode @exec_mode = :strict return @exec_mode end if [:lazy, false].include? mode @exec_mode = :lazy return @exec_mode end raise 'DSL Interpreter: Invalid execution mode !' end
exec_strict_mode?()
click to toggle source
# File lib/dsl_companion/interpreter.rb, line 51 def exec_strict_mode? @exec_mode == :strict end
method_missing(symbolic_name, *args)
click to toggle source
# File lib/dsl_companion/interpreter.rb, line 61 def method_missing(symbolic_name, *args) method_name ||= symbolic_name.to_s message = "DSL Interpreter: method '#{method_name}'" message += block_given? ? ' (with a code block passed).' : ' (with no code block passed)' message += ' is unknown' message += " within DSL file: '#{@source_code_file}'" unless @source_code_file.nil? message += '.' logger message, :error unless exec_strict_mode? raise message if exec_strict_mode? end
run(file=nil, &block)
click to toggle source
# File lib/dsl_companion/interpreter.rb, line 19 def run(file=nil, &block) if file.nil? self.instance_eval &block else @source_code_file = file code = File.read file self.instance_eval code end ensure @last_source_code_file = @source_code_file @source_code_file = nil end