Class: DataMapper::Associations::OneToOne::Relationship

Inherits:
Relationship
  • Object
show all
Defined in:
lib/dm-core/associations/one_to_one.rb

Constant Summary

Constants inherited from Relationship

Relationship::OPTIONS

Instance Attribute Summary

Attributes inherited from Relationship

#child_repository_name, #instance_variable_name, #max, #min, #name, #options, #parent_repository_name, #query, #reader_visibility, #writer_visibility

Instance Method Summary collapse

Methods inherited from Relationship

#==, #child_key, #child_model, #child_model?, #child_model_name, #eager_load, #eql?, #field, #hash, #inverse, #loaded?, #parent_key, #parent_model, #parent_model?, #parent_model_name, #query_for, #relative_target_repository_name, #relative_target_repository_name_for, #source_scope, #valid?

Methods included from Subject

#default?

Methods included from DataMapper::Assertions

#assert_kind_of

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.



80
81
82
# File 'lib/dm-core/associations/one_to_one.rb', line 80

def method_missing(method, *args, &block)
  relationship.send(method, *args, &block)
end

Instance Method Details

#default_for(source) ⇒ Object



46
47
48
# File 'lib/dm-core/associations/one_to_one.rb', line 46

def default_for(source)
  relationship.default_for(source).first
end

#get(source, query = nil) ⇒ Object

Loads (if necessary) and returns association target for given source



18
19
20
# File 'lib/dm-core/associations/one_to_one.rb', line 18

def get(source, query = nil)
  relationship.get(source, query).first
end

#get!(source) ⇒ Object

Get the resource directly



25
26
27
28
# File 'lib/dm-core/associations/one_to_one.rb', line 25

def get!(source)
  collection = relationship.get!(source)
  collection.first if collection
end

#instance_of?(klass) ⇒ Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/dm-core/associations/one_to_one.rb', line 56

def instance_of?(klass)
  super || relationship.instance_of?(klass)
end

#kind_of?(klass) ⇒ Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/dm-core/associations/one_to_one.rb', line 51

def kind_of?(klass)
  super || relationship.kind_of?(klass)
end

#respond_to?(method, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/dm-core/associations/one_to_one.rb', line 61

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



34
35
36
# File 'lib/dm-core/associations/one_to_one.rb', line 34

def set(source, target)
  relationship.set(source, [ target ].compact).first
end

#set!(source, target) ⇒ Object

Sets the resource directly



41
42
43
# File 'lib/dm-core/associations/one_to_one.rb', line 41

def set!(source, target)
  set(source, target)
end