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
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
# File 'lib/active_data/model/associations/reflections/embeds_any.rb', line 6
def self.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 = Class.new(superclass || ActiveData::Base) do
include ActiveData::Model
include ActiveData::Model::Associations
include ActiveData::Model::Lifecycle
include ActiveData::Model::Primary
end
target.const_set(name.to_s.classify, klass)
klass.class_eval(&block)
klass
end
end
super
end
|
Instance Method Details
36
37
38
|
# File 'lib/active_data/model/associations/reflections/embeds_any.rb', line 36
def embedded?
true
end
|
#inspect ⇒ Object
32
33
34
|
# File 'lib/active_data/model/associations/reflections/embeds_any.rb', line 32
def inspect
"#{self.class.name.demodulize}(#{klass})"
end
|
#klass ⇒ Object
24
25
26
27
28
29
30
|
# File 'lib/active_data/model/associations/reflections/embeds_any.rb', line 24
def klass
@klass ||= if options[:class]
options[:class].call(self)
else
super
end
end
|