Class: Lotus::Model::Adapters::Memory::Collection Private
- Inherits:
-
Object
- Object
- Lotus::Model::Adapters::Memory::Collection
- Defined in:
- lib/lotus/model/adapters/memory/collection.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Acts like a SQL database table.
Defined Under Namespace
Classes: PrimaryKey
Instance Attribute Summary collapse
- #identity ⇒ Object readonly private
- #name ⇒ Object readonly private
- #records ⇒ Object readonly private
Instance Method Summary collapse
-
#all ⇒ Array<Hash>
private
Returns all the raw records.
-
#clear ⇒ Object
private
Deletes all the records and resets the identity counter.
-
#create(entity) ⇒ Object
private
Creates a record for the given entity and assigns an id.
-
#delete(entity) ⇒ Object
private
Deletes the record corresponding to the given entity.
-
#initialize(name, identity) ⇒ Collection
constructor
private
Initialize a collection.
-
#update(entity) ⇒ Object
private
Updates the record corresponding to the given entity.
Constructor Details
#initialize(name, identity) ⇒ Collection
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Initialize a collection
64 65 66 67 |
# File 'lib/lotus/model/adapters/memory/collection.rb', line 64 def initialize(name, identity) @name, @identity = name, identity clear end |
Instance Attribute Details
#identity ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
48 49 50 |
# File 'lib/lotus/model/adapters/memory/collection.rb', line 48 def identity @identity end |
#name ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
41 42 43 |
# File 'lib/lotus/model/adapters/memory/collection.rb', line 41 def name @name end |
#records ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
54 55 56 |
# File 'lib/lotus/model/adapters/memory/collection.rb', line 54 def records @records end |
Instance Method Details
#all ⇒ Array<Hash>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns all the raw records
116 117 118 |
# File 'lib/lotus/model/adapters/memory/collection.rb', line 116 def all records.values end |
#clear ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Deletes all the records and resets the identity counter.
124 125 126 127 |
# File 'lib/lotus/model/adapters/memory/collection.rb', line 124 def clear @records = {} @primary_key = PrimaryKey.new end |
#create(entity) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Creates a record for the given entity and assigns an id.
79 80 81 82 83 84 |
# File 'lib/lotus/model/adapters/memory/collection.rb', line 79 def create(entity) @primary_key.increment! do |id| entity[identity] = id records[id] = entity end end |
#delete(entity) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Deletes the record corresponding to the given entity.
106 107 108 |
# File 'lib/lotus/model/adapters/memory/collection.rb', line 106 def delete(entity) records.delete(entity.id) end |
#update(entity) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Updates the record corresponding to the given entity.
94 95 96 |
# File 'lib/lotus/model/adapters/memory/collection.rb', line 94 def update(entity) records[entity.fetch(identity)] = entity end |