Class: Cuca::Generator::View::AssignBindings

Inherits:
Object
  • Object
show all
Defined in:
lib/cuca/generator/view.rb

Overview

:nodoc:

Instance Method Summary collapse

Constructor Details

#initialize(assigns, base_object) ⇒ AssignBindings

Returns a new instance of AssignBindings.



48
49
50
51
52
53
# File 'lib/cuca/generator/view.rb', line 48

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



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/cuca/generator/view.rb', line 55

def method_missing(sym, *args, &block )
  class_name = sym.id2name

  begin
     # 1st try to find method in the base widget
     if @base.methods.include?(class_name) then 
         return @base.send(class_name, *args, &block)
     end
     # 2nd try to find a widget
     c=Object::const_get(class_name+"Widget")
  rescue NameError => e
     raise "Undefined method: #{sym.id2name}"
  end

  widget = c.new({:args => args,
                :assigns => @assigns },
                &block)

#     $stderr.puts "Widget:" + widget.inspect
  return widget.to_s

#     $stderr.puts "Good"
end

Instance Method Details

#get_bindingsObject



44
45
46
# File 'lib/cuca/generator/view.rb', line 44

def get_bindings
   binding
end