Method: Glimmer#method_missing

Defined in:
lib/glimmer.rb

#method_missing(method_symbol, *args, &block) ⇒ Object


59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/glimmer.rb', line 59

def method_missing(method_symbol, *args, &block)
  # This if statement speeds up Glimmer in girb or whenever directly including on main object
  is_excluded = Config.excluded_keyword_checkers.any? do |checker|
    instance_exec(method_symbol, *args, &checker)
  end
  if is_excluded
    Glimmer::Config.logger.debug "Glimmer excluded keyword: #{method_symbol}" if Glimmer::Config.log_excluded_keywords?
    super(method_symbol, *args, &block)
  else
    new_loop_data = [method_symbol, args, block]
    if new_loop_data == Glimmer.loop_last_data
      Glimmer.loop_increment!
      raise "Glimmer looped #{Config.loop_max_count} times with keyword '#{new_loop_data[0]}'! Check code for errors." if Glimmer.loop == Config.loop_max_count
    else
      Glimmer.loop_reset!
    end
    Glimmer.loop_last_data = new_loop_data
    Glimmer::Config.logger.info {">"*80}
    Glimmer::Config.logger.info {"Interpreting keyword: #{method_symbol}"}
    Glimmer::DSL::Engine.interpret(method_symbol, *args, &block)
  end
rescue InvalidKeywordError => e
  Glimmer::Config.logger.error {"Encountered an invalid keyword '#{method_symbol}' at this object: #{self.inspect}"}
  Glimmer::Config.logger.error {e.full_message}
  super(method_symbol, *args, &block)
end