Class: DuckRecord::Associations::EmbedsOneAssociation

Inherits:
EmbedsAssociation show all
Defined in:
lib/duck_record/associations/embeds_one_association.rb

Overview

:nodoc:

Instance Attribute Summary

Attributes inherited from EmbedsAssociation

#owner, #reflection, #target

Instance Method Summary collapse

Methods inherited from EmbedsAssociation

#initialize, #initialize_attributes, #klass, #loaded?, #marshal_dump, #marshal_load, #reset

Constructor Details

This class inherits a constructor from DuckRecord::Associations::EmbedsAssociation

Instance Method Details

#build(attributes = {}) {|record| ... } ⇒ Object

Yields:

  • (record)


14
15
16
17
18
19
# File 'lib/duck_record/associations/embeds_one_association.rb', line 14

def build(attributes = {})
  record = build_record(attributes)
  yield(record) if block_given?
  set_new_record(record)
  record
end

#force_reload_readerObject

Implements the reload reader method, e.g. foo.reload_bar for Foo.has_one :bar



23
24
25
26
# File 'lib/duck_record/associations/embeds_one_association.rb', line 23

def force_reload_reader
  klass.uncached { reload }
  target
end

#readerObject

Implements the reader method, e.g. foo.bar for Foo.has_one :bar



5
6
7
# File 'lib/duck_record/associations/embeds_one_association.rb', line 5

def reader
  target
end

#writer(record) ⇒ Object

Implements the writer method, e.g. foo.bar= for Foo.belongs_to :bar



10
11
12
# File 'lib/duck_record/associations/embeds_one_association.rb', line 10

def writer(record)
  replace(record)
end