Class: MongoModel::Associations::Base::Association

Inherits:
Object
  • Object
show all
Defined in:
lib/mongomodel/concerns/associations/base/association.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(definition, instance) ⇒ Association

Returns a new instance of Association


10
11
12
# File 'lib/mongomodel/concerns/associations/base/association.rb', line 10

def initialize(definition, instance)
  @definition, @instance = definition, instance
end

Instance Attribute Details

#definitionObject (readonly)

Returns the value of attribute definition


7
8
9
# File 'lib/mongomodel/concerns/associations/base/association.rb', line 7

def definition
  @definition
end

#instanceObject (readonly)

Returns the value of attribute instance


7
8
9
# File 'lib/mongomodel/concerns/associations/base/association.rb', line 7

def instance
  @instance
end

Instance Method Details

#ensure_class(value) ⇒ Object


23
24
25
26
27
# File 'lib/mongomodel/concerns/associations/base/association.rb', line 23

def ensure_class(value)
  unless value.is_a?(klass) || value.class.name.constantize <= klass.name.constantize
    raise AssociationTypeMismatch, "#{klass} expected, got #{value.class}"
  end
end

#proxyObject


14
15
16
# File 'lib/mongomodel/concerns/associations/base/association.rb', line 14

def proxy
  @proxy ||= proxy_class.new(self)
end

#replace(obj) ⇒ Object


18
19
20
21
# File 'lib/mongomodel/concerns/associations/base/association.rb', line 18

def replace(obj)
  proxy.target = obj
  proxy
end