Sha256: a2f8eb111589578c78a858f081b879df387bf962983b7e60da0f6770a98b95b7
Contents?: true
Size: 1.18 KB
Versions: 1
Compression:
Stored size: 1.18 KB
Contents
module Rico class Collection include Rico::Object include Enumerable extend Forwardable def_delegators :members, :each, :[], :length, :count # Adds the requested items to the array and stores the object # # items - items to be added to the array # # Returns the result of the store operation def add(*items) mutate build_map_add(items) end # Removes the requested items from the array and stores the object # # items - items to be removed from the array # # Returns the result of the store operation def remove(*items) mutate build_map_remove(items) end # Tests whether or not an item exists in the array # # item - item to test against # # Returns true or false def member?(item) members.include? item end protected def build_map_add(items) { "_type" => type_key, "_values" => compute_add(items) } end def build_map_remove(items) { "_type" => type_key, "_values" => compute_remove(items), "_deletes" => items } end def compute_add(items) members + items end def compute_remove(items) members - items end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
rico-0.3.0 | lib/rico/collection.rb |