module DSLCompanion::Features::Basic
Public Instance Methods
define(*args, &block)
click to toggle source
If any method named define_<something>(*args) is in the DSL, then it provides an alternate
generic syntax of define(:something, *args)
@param [Object[]] args @param [Proc] block @return [Anything returned by the method]
# File lib/dsl_companion/features/basic.rb, line 13 def define(*args, &block) extra = args.shift method_name = "define_#{extra}" if respond_to? method_name.to_sym block_given? ? self.send(method_name, *args, &block) : self.send(method_name, *args) else block_given? ? method_missing(method_name.to_sym, *args, &block) : method_missing(method_name.to_sym, *args) end end
execute_within_context(context=@context, &block)
click to toggle source
# File lib/dsl_companion/features/basic.rb, line 23 def execute_within_context(context=@context, &block) # Execute the block if any if block_given? last_saved_context = @current_context @current_context = context begin logger "Switching to context: #{@current_context} (from #{last_saved_context})" MetaHelper.inject_variable @current_context, :interpreter, @interpreter @current_context.instance_eval(&block) ensure @current_context = last_saved_context logger "Back to context: #{@current_context}" end end end
interpreter()
click to toggle source
# File lib/dsl_companion/features/basic.rb, line 43 def interpreter self if interpreter? end
interpreter?()
click to toggle source
# File lib/dsl_companion/features/basic.rb, line 39 def interpreter? self.is_a? DSLCompanion::Interpreter end
logger(msg, level=:debug)
click to toggle source
# File lib/dsl_companion/features/basic.rb, line 47 def logger(msg, level=:debug) if @logger.nil? STDERR.puts "#{level.to_s.upcase}: #{msg}" else @logger.send level, msg end end