Class: Palsy::Collection
- Includes:
- Enumerable
- Defined in:
- lib/palsy/basic/collection.rb
Overview
Base class for Collections. This includes Enumerable and makes the object name a required value. That’s literally all it does.
For more information on how to use this, see Palsy::Generic. If you want to exploit the Enumerable mixin, you need to define #each.
Almost all Palsy::Collection objects are instantiated this way (using Palsy::Map as an example):
obj = Palsy::Map.new("some_maps", "a_specific_map")
obj[1] = 2
obj[1] == 2 #=> true
This will create a table called “some_maps” and all i/o will be directed to that table with an additional key of “a_specific_map”. This allows you to coordinate multiple maps in a single table.
Another example:
obj1 = Palsy::Map.new("some_maps", "a_specific_map")
obj2 = Palsy::Map.new("some_maps", "a_specific_map")
obj3 = Palsy::Map.new("some_maps", "a_different_map")
obj1 == obj2 #=> true
obj1[1] = 2
obj2[1] == 2 #=> also true
obj3 == obj1 #=> false (different map keys)
obj3[1] = 3
obj2[1] == 3 #=> also false
Instance Attribute Summary
Attributes inherited from Generic
#db, #object_name, #table_name
Instance Method Summary collapse
-
#initialize(table_name, object_name) ⇒ Collection
constructor
See the documentation for Palsy::Collection.
Methods inherited from Generic
#==, #_dump, _load, #create_table, #post_marshal_init
Constructor Details
#initialize(table_name, object_name) ⇒ Collection
See the documentation for Palsy::Collection.
41 42 43 44 |
# File 'lib/palsy/basic/collection.rb', line 41 def initialize(table_name, object_name) raise "an object_name must be provided!" unless object_name super end |