Module: Masterman::Reflection
- Included in:
- Base
- Defined in:
- lib/masterman/reflection.rb,
lib/masterman/reflection/macro.rb
Defined Under Namespace
Classes: BelongsToReflection, HasManyReflection, HasOneReflection, Macro, SinglurReflection, ThroughReflection
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.add_reflection(masterman_base, name, reflection) ⇒ Object
24
25
26
|
# File 'lib/masterman/reflection.rb', line 24
def self.add_reflection(masterman_base, name, reflection)
masterman_base._reflections.merge!(name.to_s => reflection)
end
|
.build(macro, name, scope, options, model_class) ⇒ Object
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
# File 'lib/masterman/reflection.rb', line 5
def self.build(macro, name, scope, options, model_class)
case macro
when :belongs_to
return BelongsToReflection.new(name, scope, options, model_class)
when :has_one
reflection = HasOneReflection.new(name, scope, options, model_class)
when :has_many
reflection = HasManyReflection.new(name, scope, options, model_class)
else
raise NotImplementedError, "#{macro} is not supported"
end
if options[:through]
ThroughReflection.new(reflection)
else
reflection
end
end
|
Instance Method Details
#_reflections ⇒ Object
33
34
35
|
# File 'lib/masterman/reflection.rb', line 33
def _reflections
@_reflections ||= {}
end
|
#_reflections=(val) ⇒ Object
37
38
39
|
# File 'lib/masterman/reflection.rb', line 37
def _reflections=(val)
@_reflections = val
end
|
#reflections ⇒ Object
Returns cloned reflections
29
30
31
|
# File 'lib/masterman/reflection.rb', line 29
def reflections
_reflections.clone
end
|