Class: Humanoid::Associations::BelongsTo
- Includes:
- Proxy
- Defined in:
- lib/humanoid/associations/belongs_to.rb
Overview
:nodoc:
Class Method Summary collapse
-
.instantiate(document, options) ⇒ Object
Creates the new association by setting the internal document as the passed in Document.
-
.macro ⇒ Object
Returns the macro used to create the association.
-
.update(target, child, options) ⇒ Object
Perform an update of the relationship of the parent and child.
Instance Method Summary collapse
-
#find(id) ⇒ Object
Returns the parent document.
-
#initialize(target, options) ⇒ BelongsTo
constructor
Creates the new association by setting the internal target as the passed in Document.
Methods included from Proxy
Constructor Details
#initialize(target, options) ⇒ BelongsTo
Creates the new association by setting the internal target as the passed in Document. This should be the parent.
All method calls on this object will then be delegated to the internal document itself.
Options:
target: The parent Document
options: The association options
18 19 20 21 |
# File 'lib/humanoid/associations/belongs_to.rb', line 18 def initialize(target, ) @target, @options = target, extends() end |
Class Method Details
.instantiate(document, options) ⇒ Object
Creates the new association by setting the internal document as the passed in Document. This should be the parent.
Options:
document: The parent Document
options: The association options
39 40 41 42 |
# File 'lib/humanoid/associations/belongs_to.rb', line 39 def instantiate(document, ) target = document._parent target.nil? ? nil : new(target, ) end |
.macro ⇒ Object
Returns the macro used to create the association.
45 46 47 |
# File 'lib/humanoid/associations/belongs_to.rb', line 45 def macro :belongs_to end |
.update(target, child, options) ⇒ Object
Perform an update of the relationship of the parent and child. This is initialized by setting a parent object as the association on the Document
. Will properly set a has_one or a has_many.
Returns:
A new BelongsTo
association proxy.
56 57 58 59 60 |
# File 'lib/humanoid/associations/belongs_to.rb', line 56 def update(target, child, ) child.parentize(target, .inverse_of) child.notify instantiate(child, ) end |
Instance Method Details
#find(id) ⇒ Object
Returns the parent document. The id param is present for compatibility with rails, however this could be overwritten in the future.
26 27 28 |
# File 'lib/humanoid/associations/belongs_to.rb', line 26 def find(id) @target end |