Module: Origen::Controller::ClassMethods

Defined in:
lib/origen/controller.rb

Instance Method Summary collapse

Instance Method Details

#_namespaceObject


43
44
45
# File 'lib/origen/controller.rb', line 43

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

#_resolve_model_class(options) ⇒ Object


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/origen/controller.rb', line 20

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


6
7
8
9
10
11
12
13
14
# File 'lib/origen/controller.rb', line 6

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


16
17
18
# File 'lib/origen/controller.rb', line 16

def path_to_model
  @path_to_model
end