Class: Ripple::Associations::ManyLinkedProxy

Inherits:
Proxy show all
Includes:
Linked, Many
Defined in:
lib/ripple/associations/many_linked_proxy.rb

Instance Attribute Summary

Attributes inherited from Proxy

#owner, #reflection, #target

Instance Method Summary collapse

Methods included from Linked

#include?, #keys, #replace, #replace_links

Methods included from Many

#to_ary

Methods included from Instantiators

#build, #create, #create!

Methods inherited from Proxy

#===, #blank?, #has_changed_documents?, #initialize, #inspect, #loaded, #loaded?, #nil?, #present?, #proxy_respond_to?, #reload, #replace, #respond_to?, #send

Constructor Details

This class inherits a constructor from Ripple::Associations::Proxy

Dynamic Method Handling

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

Instance Method Details

#<<(value) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/ripple/associations/many_linked_proxy.rb', line 16

def <<(value)
  if loaded?
    new_target = @target.concat(Array.wrap(value))
    replace new_target
  else
    @reflection.verify_type!([value], @owner)
    @owner.robject.links << value.to_link(@reflection.link_tag)
    appended_documents << value
    @keys = nil
  end

  self
end

#countObject



11
12
13
14
# File 'lib/ripple/associations/many_linked_proxy.rb', line 11

def count
  # avoid having to load all documents by using our keys set instead
  keys.size
end

#delete(value) ⇒ Object



30
31
32
33
34
35
# File 'lib/ripple/associations/many_linked_proxy.rb', line 30

def delete(value)
  load_target
  @target.delete(value)
  replace @target
  self
end

#loaded_documentsObject



42
43
44
# File 'lib/ripple/associations/many_linked_proxy.rb', line 42

def loaded_documents
  (super + appended_documents).uniq
end

#resetObject



37
38
39
40
# File 'lib/ripple/associations/many_linked_proxy.rb', line 37

def reset
  @appended_documents = nil
  super
end