Class: Granite::Form::Model::Associations::Reflections::EmbedsAny

Inherits:
Base
  • Object
show all
Defined in:
lib/granite/form/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 Granite::Form::Model::Associations::Reflections::Base

Class Method Details

.build(target, generated_methods, name, options = {}, &block) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/granite/form/model/associations/reflections/embeds_any.rb', line 8

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:



44
45
46
# File 'lib/granite/form/model/associations/reflections/embeds_any.rb', line 44

def embedded?
  true
end

#inspectObject



40
41
42
# File 'lib/granite/form/model/associations/reflections/embeds_any.rb', line 40

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

#klassObject



32
33
34
35
36
37
38
# File 'lib/granite/form/model/associations/reflections/embeds_any.rb', line 32

def klass
  @klass ||= if options[:class]
               options[:class].call(self)
             else
               super
             end
end