Class: Ripple::Associations::ManyStoredKeyProxy

Inherits:
Proxy
  • Object
show all
Includes:
Many
Defined in:
lib/ripple/associations/many_stored_key_proxy.rb

Instance Attribute Summary

Attributes inherited from Proxy

#owner, #reflection, #target

Instance Method Summary collapse

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?, #loaded_documents, #nil?, #present?, #proxy_respond_to?, #reload, #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



13
14
15
16
17
18
19
20
21
22
# File 'lib/ripple/associations/many_stored_key_proxy.rb', line 13

def <<(value)
  @reflection.verify_type!([value], @owner)

  raise "Unable to append if the document isn't first saved." if value.new_record?
  load_target
  @target << value
  keys << value.key

  self
end

#countObject



9
10
11
# File 'lib/ripple/associations/many_stored_key_proxy.rb', line 9

def count
  keys.size
end

#delete(value) ⇒ Object



33
34
35
36
# File 'lib/ripple/associations/many_stored_key_proxy.rb', line 33

def delete(value)
  keys.delete(value.key)
  self
end

#include?(document) ⇒ Boolean

Returns:



51
52
53
54
55
# File 'lib/ripple/associations/many_stored_key_proxy.rb', line 51

def include?(document)
  return false unless document.respond_to?(:robject)
  return false unless document.robject.bucket.name == @reflection.bucket_name
  keys.include?(document.key)
end

#keysObject



38
39
40
41
42
43
44
# File 'lib/ripple/associations/many_stored_key_proxy.rb', line 38

def keys
  if @owner.send(keys_name).nil?
    reset_owner_keys
  end

  @owner.send(keys_name)
end

#replace(value) ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/ripple/associations/many_stored_key_proxy.rb', line 24

def replace(value)
  @reflection.verify_type!(value, @owner)

  reset_owner_keys
  value.each { |doc| self << doc }
  @target = value
  loaded
end

#resetObject



46
47
48
49
# File 'lib/ripple/associations/many_stored_key_proxy.rb', line 46

def reset
  super
  self.owner_keys = @owner.robject.data ? @owner.robject.data[keys_name] : []
end

#reset_owner_keysObject



57
58
59
# File 'lib/ripple/associations/many_stored_key_proxy.rb', line 57

def reset_owner_keys
  self.owner_keys = []
end