Class: DataMapper::Associations::OneToOne::Relationship
- Inherits:
-
Relationship
- Object
- Relationship
- DataMapper::Associations::OneToOne::Relationship
- Defined in:
- lib/dm-core/associations/one_to_one.rb
Constant Summary
Constants inherited from Relationship
Instance Attribute Summary
Attributes inherited from Relationship
#child_repository_name, #instance_variable_name, #max, #min, #name, #options, #parent_repository_name, #query
Instance Method Summary collapse
-
#get(source, other_query = nil) ⇒ Object
Loads (if necessary) and returns association target for given source.
-
#instance_of?(klass) ⇒ Boolean
TODO: document.
-
#kind_of?(klass) ⇒ Boolean
TODO: document.
-
#respond_to?(method, include_private = false) ⇒ Boolean
TODO: document.
-
#set(source, target) ⇒ Object
Sets and returns association target for given source.
Methods inherited from Relationship
#==, #child_key, #child_model, #child_model?, #child_model_name, #eager_load, #eql?, #get!, #inverse, #loaded?, #parent_key, #parent_model, #parent_model?, #parent_model_name, #query_for, #relative_target_repository_name, #relative_target_repository_name_for, #set!, #source_scope, #valid?
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
TODO: document
68 69 70 |
# File 'lib/dm-core/associations/one_to_one.rb', line 68 def method_missing(method, *args, &block) relationship.send(method, *args, &block) end |
Instance Method Details
#get(source, other_query = nil) ⇒ Object
Loads (if necessary) and returns association target for given source
15 16 17 18 19 20 21 |
# File 'lib/dm-core/associations/one_to_one.rb', line 15 def get(source, other_query = nil) assert_kind_of 'source', source, source_model return unless loaded?(source) || source_key.get(source).all? relationship.get(source, other_query).first end |
#instance_of?(klass) ⇒ Boolean
TODO: document
42 43 44 |
# File 'lib/dm-core/associations/one_to_one.rb', line 42 def instance_of?(klass) super || relationship.instance_of?(klass) end |
#kind_of?(klass) ⇒ Boolean
TODO: document
36 37 38 |
# File 'lib/dm-core/associations/one_to_one.rb', line 36 def kind_of?(klass) super || relationship.kind_of?(klass) end |
#respond_to?(method, include_private = false) ⇒ Boolean
TODO: document
48 49 50 |
# File 'lib/dm-core/associations/one_to_one.rb', line 48 def respond_to?(method, include_private = false) super || relationship.respond_to?(method, include_private) end |
#set(source, target) ⇒ Object
Sets and returns association target for given source
27 28 29 30 31 32 |
# File 'lib/dm-core/associations/one_to_one.rb', line 27 def set(source, target) assert_kind_of 'source', source, source_model assert_kind_of 'target', target, target_model, Hash, NilClass relationship.set(source, [ target ].compact).first end |