Class: GeneratorContext
- Inherits:
-
Object
- Object
- GeneratorContext
- Defined in:
- lib/cuca/generator_context.rb
Overview
A good context for generators. It will find and run widgets on method_missing.
Instance Method Summary collapse
- #get_bindings ⇒ Object
-
#initialize(assigns, base_object) ⇒ GeneratorContext
constructor
A new instance of GeneratorContext.
- #method_missing(sym, *args, &block) ⇒ Object
Constructor Details
#initialize(assigns, base_object) ⇒ GeneratorContext
Returns a new instance of GeneratorContext.
8 9 10 11 12 13 |
# File 'lib/cuca/generator_context.rb', line 8 def initialize(assigns, base_object) assigns.each_pair do |k,v| instance_variable_set("@#{k}", v) end @base = base_object end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(sym, *args, &block) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/cuca/generator_context.rb', line 15 def method_missing(sym, *args, &block ) class_name = sym.id2name # 1st try to find method in the base widget if @base.respond_to?(class_name.intern) then return @base.send(class_name, *args, &block) end c = nil # 2nd try to find a widget if Object.const_defined?(class_name+'Widget') then c = Object::const_get(class_name+'Widget') else # ...try to find in action namespace mod = $app.urlmap.action_module c = mod.const_get(class_name+'Widget') if mod.const_defined?(class_name+'Widget') end raise NameError.new "Undefined method: #{class_name}" unless c = c.new({:args => args, :assigns => @assigns }, &block) return .to_s end |
Instance Method Details
#get_bindings ⇒ Object
4 5 6 |
# File 'lib/cuca/generator_context.rb', line 4 def get_bindings binding end |