Module: Ripple::Associations::Linked
- Included in:
- ManyLinkedProxy, OneLinkedProxy
- Defined in:
- lib/ripple/associations/linked.rb
Instance Method Summary collapse
- #include?(document) ⇒ Boolean
- #keys ⇒ Object
- #replace(value) ⇒ Object
- #replace_links(value) ⇒ Object
- #reset ⇒ Object
Instance Method Details
#include?(document) ⇒ Boolean
35 36 37 38 39 40 41 42 |
# File 'lib/ripple/associations/linked.rb', line 35 def include?(document) return false unless document.respond_to?(:robject) # TODO: when we allow polymorphic assocations, this will have to change # since @reflection.bucket_name will be '_' in that case. return false unless document.robject.bucket.name == @reflection.bucket_name keys.include?(document.key) end |
#keys ⇒ Object
26 27 28 |
# File 'lib/ripple/associations/linked.rb', line 26 def keys @keys ||= Set.new(links.map { |l| l.key }) end |
#replace(value) ⇒ Object
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/ripple/associations/linked.rb', line 7 def replace(value) @reflection.verify_type!(value, @owner) @owner.robject.links -= links Array.wrap(value).compact.each do |doc| @owner.robject.links << doc.to_link(@reflection.link_tag) end loaded @keys = nil @target = value end |
#replace_links(value) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/ripple/associations/linked.rb', line 18 def replace_links(value) @owner.robject.links -= links Array(value).each do |link| @owner.robject.links << link end reset end |
#reset ⇒ Object
30 31 32 33 |
# File 'lib/ripple/associations/linked.rb', line 30 def reset super @keys = nil end |