Class: Masterman::Reflection::Macro
- Inherits:
-
Object
- Object
- Masterman::Reflection::Macro
show all
- Defined in:
- lib/masterman/reflection/macro.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(name, scope, options, model_class) ⇒ Macro
Returns a new instance of Macro.
6
7
8
9
10
11
|
# File 'lib/masterman/reflection/macro.rb', line 6
def initialize(name, scope, options, model_class)
@name = name
@scope = scope
@options = options
@model_class = model_class
end
|
Instance Attribute Details
#model_class ⇒ Object
Returns the value of attribute model_class.
4
5
6
|
# File 'lib/masterman/reflection/macro.rb', line 4
def model_class
@model_class
end
|
#name ⇒ Object
Returns the value of attribute name.
4
5
6
|
# File 'lib/masterman/reflection/macro.rb', line 4
def name
@name
end
|
#options ⇒ Object
Returns the value of attribute options.
4
5
6
|
# File 'lib/masterman/reflection/macro.rb', line 4
def options
@options
end
|
#scope ⇒ Object
Returns the value of attribute scope.
4
5
6
|
# File 'lib/masterman/reflection/macro.rb', line 4
def scope
@scope
end
|
Instance Method Details
#build_association(instance, reflection) ⇒ Object
21
22
23
|
# File 'lib/masterman/reflection/macro.rb', line 21
def build_association(instance, reflection)
Masterman::Association.new(instance, reflection)
end
|
#collection? ⇒ Boolean
35
36
37
|
# File 'lib/masterman/reflection/macro.rb', line 35
def collection?
raise NotImplementedError, 'collection? is not defined'
end
|
#foreign_key ⇒ Object
13
14
15
|
# File 'lib/masterman/reflection/macro.rb', line 13
def foreign_key
(options[:foreign_key] || "#{name.to_s}_id").to_s
end
|
#klass ⇒ Object
25
26
27
|
# File 'lib/masterman/reflection/macro.rb', line 25
def klass
@klass ||= compute_class(class_name)
end
|
#macro ⇒ Object
17
18
19
|
# File 'lib/masterman/reflection/macro.rb', line 17
def macro
raise NotImplementedError, 'macro is not defined'
end
|
#through_reflection ⇒ Object
29
30
31
32
33
|
# File 'lib/masterman/reflection/macro.rb', line 29
def through_reflection
if options[:through]
model_class._reflections[options[:through].to_s]
end
end
|