Module: Seabright::Collections::ClassMethods
- Defined in:
- lib/redis_object/collection.rb
Instance Method Summary collapse
- #<<(obj) ⇒ Object
- #collection_name ⇒ Object
- #collections ⇒ Object
- #delete_child(obj) ⇒ Object
- #get(k) ⇒ Object
- #get_collection(name) ⇒ Object
- #has_collection?(name) ⇒ Boolean
- #hkey_col(ident = nil) ⇒ Object
- #push(obj) ⇒ Object
- #reference(obj) ⇒ Object
- #remove_collection!(name) ⇒ Object
Instance Method Details
#<<(obj) ⇒ Object
159 160 161 |
# File 'lib/redis_object/collection.rb', line 159 def <<(obj) reference obj end |
#collection_name ⇒ Object
149 150 151 |
# File 'lib/redis_object/collection.rb', line 149 def collection_name self.name.split('::').last.pluralize.underscore.to_sym end |
#collections ⇒ Object
190 191 192 |
# File 'lib/redis_object/collection.rb', line 190 def collections @collections ||= {} end |
#delete_child(obj) ⇒ Object
143 144 145 146 147 |
# File 'lib/redis_object/collection.rb', line 143 def delete_child(obj) if col = get_collection(obj.collection_name) col.delete obj end end |
#get(k) ⇒ Object
171 172 173 174 175 176 177 178 179 |
# File 'lib/redis_object/collection.rb', line 171 def get(k) if has_collection?(k) get_collection(k) elsif has_collection?(pk = k.to_s.pluralize) get_collection(pk).first else super(k) end end |
#get_collection(name) ⇒ Object
185 186 187 188 |
# File 'lib/redis_object/collection.rb', line 185 def get_collection(name) collections[name.to_s] ||= Collection.load(name,self) collections[name.to_s] end |
#has_collection?(name) ⇒ Boolean
181 182 183 |
# File 'lib/redis_object/collection.rb', line 181 def has_collection?(name) store.sismember(hkey_col,name.to_s) end |
#hkey_col(ident = nil) ⇒ Object
139 140 141 |
# File 'lib/redis_object/collection.rb', line 139 def hkey_col(ident = nil) "#{hkey(ident)}:collections" end |
#push(obj) ⇒ Object
163 164 165 |
# File 'lib/redis_object/collection.rb', line 163 def push(obj) reference obj end |
#reference(obj) ⇒ Object
153 154 155 156 157 |
# File 'lib/redis_object/collection.rb', line 153 def reference(obj) name = obj.collection_name store.sadd hkey_col, name get_collection(name) << obj.hkey end |
#remove_collection!(name) ⇒ Object
167 168 169 |
# File 'lib/redis_object/collection.rb', line 167 def remove_collection!(name) store.srem hkey_col, name end |