Class: ActiveData::Model::Associations::Reflections::EmbedsAny
- Inherits:
-
Base
- Object
- Base
- ActiveData::Model::Associations::Reflections::EmbedsAny
show all
- Defined in:
- lib/active_data/model/associations/reflections/embeds_any.rb
Constant Summary
Constants inherited
from Base
Base::READ, Base::WRITE
Instance Attribute Summary
Attributes inherited from Base
#name, #options, #parent_reflection
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Base
association_class, #belongs_to?, #build_association, #collection?, #default, generate_methods, #initialize, #macro, #read_source, #write_source
Class Method Details
.build(target, generated_methods, name, options = {}, &block) ⇒ Object
7
8
9
10
11
12
13
14
15
16
17
18
|
# File 'lib/active_data/model/associations/reflections/embeds_any.rb', line 7
def build(target, generated_methods, name, options = {}, &block)
if block
options[:class] = proc do |reflection|
superclass = reflection.options[:class_name].to_s.presence.try(:constantize)
klass = build_class(superclass)
target.const_set(name.to_s.classify, klass)
klass.class_eval(&block)
klass
end
end
super
end
|
Instance Method Details
43
44
45
|
# File 'lib/active_data/model/associations/reflections/embeds_any.rb', line 43
def embedded?
true
end
|
#inspect ⇒ Object
39
40
41
|
# File 'lib/active_data/model/associations/reflections/embeds_any.rb', line 39
def inspect
"#{self.class.name.demodulize}(#{klass})"
end
|
#klass ⇒ Object
31
32
33
34
35
36
37
|
# File 'lib/active_data/model/associations/reflections/embeds_any.rb', line 31
def klass
@klass ||= if options[:class]
options[:class].call(self)
else
super
end
end
|