Class: ActiveData::Model::Associations::Reflections::EmbedsAny

Inherits:
Base
  • Object
show all
Defined in:
lib/active_data/model/associations/reflections/embeds_any.rb

Direct Known Subclasses

EmbedsMany, EmbedsOne

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

Constructor Details

This class inherits a constructor from ActiveData::Model::Associations::Reflections::Base

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

#embedded?Boolean

Returns:



43
44
45
# File 'lib/active_data/model/associations/reflections/embeds_any.rb', line 43

def embedded?
  true
end

#inspectObject



39
40
41
# File 'lib/active_data/model/associations/reflections/embeds_any.rb', line 39

def inspect
  "#{self.class.name.demodulize}(#{klass})"
end

#klassObject



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