Sha256: 3f4402bbd38c37cde63efe47ba1421c4ae6dbf2bd5d293e746f168934cbd838e
Contents?: true
Size: 1.56 KB
Versions: 6
Compression:
Stored size: 1.56 KB
Contents
require 'ripple/associations/proxy' require 'ripple/associations/many' module Ripple module Associations class ManyStoredKeyProxy < Proxy include Many def count keys.size end 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 def replace(value) @reflection.verify_type!(value, @owner) reset_owner_keys value.each { |doc| self << doc } @target = value loaded end def delete(value) keys.delete(value.key) self end def keys if @owner.send(keys_name).nil? reset_owner_keys end @owner.send(keys_name) end def reset super self.owner_keys = @owner.robject.data ? @owner.robject.data[keys_name] : [] end 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 def reset_owner_keys self.owner_keys = [] end protected def find_target klass.find(keys.to_a) end def keys_name "#{@reflection.name.to_s.singularize}_keys" end def owner_keys=(new_keys) @owner.send("#{keys_name}=", @owner.class.properties[keys_name].type.new(new_keys)) end end end end
Version data entries
6 entries across 5 versions & 4 rubygems