Module: Origen::Controller::ClassMethods

Defined in:
lib/origen/controller.rb

Instance Method Summary collapse

Instance Method Details

#_namespaceObject



55
56
57
# File 'lib/origen/controller.rb', line 55

def _namespace
  to_s.sub(/::[^:]*$/, '')
end

#_resolve_model_class(options) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/origen/controller.rb', line 32

def _resolve_model_class(options)
  class_name = options[:class_name]
  if class_name
    if eval("defined? #{_namespace}::#{class_name}")
      klass = eval("#{_namespace}::#{class_name}")
    else
      if eval("defined? #{class_name}")
        klass = eval(class_name)
      else
        if eval("defined? #{self}::#{class_name}")
          klass = eval("#{self}::#{class_name}")
        else
          puts "Could not find class: #{class_name}"
          fail 'Unknown model class!'
        end
      end
    end
    klass
  else
    fail "You must supply a :class_name option when defining a controller's model!"
  end
end

#model(options = {}) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'lib/origen/controller.rb', line 18

def model(options = {})
  options[:controller_class] = self
  if options[:path]
    @path_to_model = options[:path]
  else
    options[:model_class] = _resolve_model_class(options)
  end
  Origen.controllers << options
end

#path_to_modelObject



28
29
30
# File 'lib/origen/controller.rb', line 28

def path_to_model
  @path_to_model
end