Class: Ripple::Associations::ManyReferenceProxy
- Inherits:
-
Proxy
show all
- Includes:
- Many
- Defined in:
- lib/ripple/associations/many_reference_proxy.rb
Instance Attribute Summary
Attributes inherited from Proxy
#owner, #reflection
Instance Method Summary
collapse
Methods included from Many
#to_ary
#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
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class Ripple::Associations::Proxy
Instance Method Details
#<<(value) ⇒ Object
11
12
13
14
15
16
17
18
19
20
|
# File 'lib/ripple/associations/many_reference_proxy.rb', line 11
def <<(value)
values = Array.wrap(value)
@reflection.verify_type!(values, @owner)
values.each {|v| assign_key(v) }
load_target
@target.merge values
self
end
|
69
70
71
72
73
74
75
|
# File 'lib/ripple/associations/many_reference_proxy.rb', line 69
def count
if loaded?
@target.count
else
keys.count
end
end
|
#delete(value) ⇒ Object
40
41
42
43
44
|
# File 'lib/ripple/associations/many_reference_proxy.rb', line 40
def delete(value)
load_target
assign_key(value, nil)
@target.delete(value)
end
|
#delete_all ⇒ Object
33
34
35
36
37
38
|
# File 'lib/ripple/associations/many_reference_proxy.rb', line 33
def delete_all
load_target
@target.each do |e|
delete(e)
end
end
|
#include?(document) ⇒ Boolean
62
63
64
65
66
67
|
# File 'lib/ripple/associations/many_reference_proxy.rb', line 62
def include?(document)
return false unless document.class.respond_to?(:bucket_name)
return false unless document.class.bucket_name == @reflection.bucket_name
keys.include?(document.key)
end
|
51
52
53
54
55
|
# File 'lib/ripple/associations/many_reference_proxy.rb', line 51
def keys
@keys ||= Ripple.client.search(klass.bucket_name, "#{key_name}: #{@owner.key}")["response"]["docs"].inject(Set.new) do |set, search_document|
set << search_document["id"]
end
end
|
#replace(value) ⇒ Object
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/ripple/associations/many_reference_proxy.rb', line 22
def replace(value)
@reflection.verify_type!(value, @owner)
delete_all
Array.wrap(value).compact.each do |doc|
assign_key(doc)
end
loaded
@keys = nil
@target = Set.new(value)
end
|
57
58
59
60
|
# File 'lib/ripple/associations/many_reference_proxy.rb', line 57
def reset
@keys = nil
super
end
|
46
47
48
49
|
# File 'lib/ripple/associations/many_reference_proxy.rb', line 46
def target
load_target
@target.to_a
end
|