Class: MarkMapper::Plugins::Associations::BelongsToPolymorphicProxy

Inherits:
Proxy
  • Object
show all
Defined in:
lib/mark_mapper/plugins/associations/belongs_to_polymorphic_proxy.rb

Instance Attribute Summary

Attributes inherited from Proxy

#association, #proxy_owner, #target

Instance Method Summary collapse

Methods inherited from Proxy

#as_json, #blank?, #initialize, #inspect, #loaded, #loaded?, #nil?, #present?, #proxy_respond_to?, #reload, #reset, #respond_to?, #send, #to_json

Constructor Details

This class inherits a constructor from MarkMapper::Plugins::Associations::Proxy

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class MarkMapper::Plugins::Associations::Proxy

Instance Method Details

#replace(doc) ⇒ Object


6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/mark_mapper/plugins/associations/belongs_to_polymorphic_proxy.rb', line 6

def replace(doc)
  if doc
    doc.save unless doc.persisted?
    id, type = doc.id, doc.class.name
  end

  proxy_owner[association.foreign_key] = id
  proxy_owner[association.type_key_name] = type
  reset
  unless doc.nil?
    loaded
    @target = doc
  end

  @target
end