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



77
78
79
80
81
82
83
84
85
86
# File 'lib/origen/controller.rb', line 77

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

#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



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

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)


64
65
66
67
68
69
70
# File 'lib/origen/controller.rb', line 64

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