Module: Origen::Controller
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/origen/controller.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
-
#controller ⇒ Object
Means that when dealing with a controller/model pair, you can always call obj.model and obj.controller to get the one you want, regardless of the one you currently have.
- #inspect ⇒ Object
- #is_a?(*args) ⇒ Boolean
-
#method_missing(method, *args, &block) ⇒ Object
Used to proxy all method and attribute requests not implemented on the controller to the model.
-
#model ⇒ Object
Returns the controller’s model.
- #respond_to?(*args) ⇒ Boolean
- #respond_to_directly?(*args) ⇒ Boolean
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
Used to proxy all method and attribute requests not implemented on the controller to the model.
On first call of a missing method a method is generated to avoid the missing lookup next time, this should be faster for repeated lookups of the same method, e.g. reg
104 105 106 107 108 109 110 111 112 113 |
# File 'lib/origen/controller.rb', line 104 def method_missing(method, *args, &block) if model.respond_to?(method) define_singleton_method(method) do |*args, &block| model.send(method, *args, &block) end send(method, *args, &block) else super end end |
Instance Method Details
#controller ⇒ Object
Means that when dealing with a controller/model pair, you can always call obj.model and obj.controller to get the one you want, regardless of the one you currently have.
84 85 86 |
# File 'lib/origen/controller.rb', line 84 def controller self end |
#inspect ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/origen/controller.rb', line 48 def inspect if model "<Model/Controller: #{model.class}:#{model.object_id}/#{self.class}:#{object_id}>" else "<Controller: #{self.class}:#{object_id}>" end end |
#is_a?(*args) ⇒ Boolean
56 57 58 59 60 61 62 |
# File 'lib/origen/controller.rb', line 56 def is_a?(*args) if model super(*args) || model.is_a?(*args) else super(*args) end end |
#model ⇒ Object
Returns the controller’s model
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/origen/controller.rb', line 65 def model @model ||= begin if self.class.path_to_model m = eval(self.class.path_to_model) if m begin m.send('_controller=', self) rescue # Model is not an Origen::Model end end m end end end |
#respond_to?(*args) ⇒ Boolean
88 89 90 |
# File 'lib/origen/controller.rb', line 88 def respond_to?(*args) super || !!(!@respond_directly && model && model.respond_to_directly?(*args)) end |
#respond_to_directly?(*args) ⇒ Boolean
92 93 94 95 96 97 |
# File 'lib/origen/controller.rb', line 92 def respond_to_directly?(*args) @respond_directly = true result = respond_to?(*args) @respond_directly = false result end |