Class: Cocooned::Association::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/cocooned/association/builder.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(record, association, options = {}) ⇒ Builder

Returns a new instance of Builder.



8
9
10
11
12
# File 'lib/cocooned/association/builder.rb', line 8

def initialize(record, association, options = {})
  @record = record
  @association = association
  @options = options.dup.symbolize_keys.reverse_merge(force_non_association_create: false, wrap_object: false)
end

Instance Attribute Details

#associationObject (readonly)

Returns the value of attribute association.



6
7
8
# File 'lib/cocooned/association/builder.rb', line 6

def association
  @association
end

#recordObject (readonly)

Returns the value of attribute record.



6
7
8
# File 'lib/cocooned/association/builder.rb', line 6

def record
  @record
end

Instance Method Details

#buildObject



14
15
16
17
18
# File 'lib/cocooned/association/builder.rb', line 14

def build
  model = reflection ? build_with_reflection : build_without_reflection
  model = options[:wrap_object].call(model) if options[:wrap_object].respond_to?(:call)
  model
end