Module: Origen::Controller

Extended by:
ActiveSupport::Concern
Defined in:
lib/origen/controller.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

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



88
89
90
91
92
93
94
95
96
97
# File 'lib/origen/controller.rb', line 88

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

#controllerObject

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.



68
69
70
# File 'lib/origen/controller.rb', line 68

def controller
  self
end

#is_a?(*args) ⇒ Boolean

Returns:

  • (Boolean)


48
49
50
51
52
53
54
# File 'lib/origen/controller.rb', line 48

def is_a?(*args)
  if model
    super(*args) || model.is_a?(*args)
  else
    super(*args)
  end
end

#modelObject

Returns the controller’s model



57
58
59
60
61
62
63
# File 'lib/origen/controller.rb', line 57

def model
  @model ||= begin
    if self.class.path_to_model
      eval(self.class.path_to_model)
    end
  end
end

#respond_to?(*args) ⇒ Boolean

Returns:

  • (Boolean)


72
73
74
# File 'lib/origen/controller.rb', line 72

def respond_to?(*args)
  super || !!(!@respond_directly && model && model.respond_to_directly?(*args))
end

#respond_to_directly?(*args) ⇒ Boolean

Returns:

  • (Boolean)


76
77
78
79
80
81
# File 'lib/origen/controller.rb', line 76

def respond_to_directly?(*args)
  @respond_directly = true
  result = respond_to?(*args)
  @respond_directly = false
  result
end