Module: Origen::Controller
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/origen/controller.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
-
#==(obj, options = {}) ⇒ Object
(also: #equal?)
When compared to another object, a controller will consider itself equal if either the controller or its model match the given object.
-
#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.
-
#display ⇒ Object
Workaround due to reserved keywords in Ruby, Display in the case below.
- #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
- #to_json(*args) ⇒ Object
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
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/origen/controller.rb', line 132 def method_missing(method, *args, &block) if model.respond_to?(method) # This method is handled separately since it is important to produce a proxy method # that takes no arguments, otherwise the register address lookup system mistakes it # for a legacy way of calculating the base address whereby the register itself was # given as an argument. if method.to_sym == :base_address define_singleton_method(method) do model.send(method) end base_address else define_singleton_method(method) do |*args, &block| model.send(method, *args, &block) end send(method, *args, &block) end else super end end |
Instance Method Details
#==(obj, options = {}) ⇒ Object Also known as: equal?
When compared to another object, a controller will consider itself equal if either the controller or its model match the given object
93 94 95 96 97 98 99 100 101 102 |
# File 'lib/origen/controller.rb', line 93 def ==(obj, = {}) if obj.is_a?(Origen::SubBlocks::Placeholder) obj = obj.materialize end if [:called_from_model] super(obj) else super(obj) || model == obj end end |
#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.
108 109 110 |
# File 'lib/origen/controller.rb', line 108 def controller self end |
#display ⇒ Object
Workaround due to reserved keywords in Ruby, Display in the case below.
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/origen/controller.rb', line 6 def display # If the DUT responds to a sub_block "display" return the sub_block if model.sub_blocks.include? 'display' Origen.log.debug "Found a sub_block \'display\', passing control to the #{model.class}..." model.sub_blocks['display'] else # Else, pass control to the ruby core. super end end |
#inspect ⇒ Object
60 61 62 63 64 65 66 |
# File 'lib/origen/controller.rb', line 60 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
68 69 70 71 72 73 74 |
# File 'lib/origen/controller.rb', line 68 def is_a?(*args) if model super(*args) || model.is_a?(*args) else super(*args) end end |
#model ⇒ Object
Returns the controller’s model
77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/origen/controller.rb', line 77 def model @model ||= if self.class.path_to_model m = eval(self.class.path_to_model) if m if m.respond_to?(:_controller=) m.send(:_controller=, self) end else fail "No model object found at path: #{self.class.path_to_model}" end m end end |
#respond_to?(*args) ⇒ Boolean
112 113 114 |
# File 'lib/origen/controller.rb', line 112 def respond_to?(*args) super || !!(!@respond_directly && model && model.respond_to_directly?(*args)) end |
#respond_to_directly?(*args) ⇒ Boolean
116 117 118 119 120 121 |
# File 'lib/origen/controller.rb', line 116 def respond_to_directly?(*args) @respond_directly = true result = respond_to?(*args) @respond_directly = false result end |
#to_json(*args) ⇒ Object
123 124 125 |
# File 'lib/origen/controller.rb', line 123 def to_json(*args) model.to_json(*args) end |