Class: Uorm::Redis::Persistance
- Inherits:
-
Struct
- Object
- Struct
- Uorm::Redis::Persistance
- Defined in:
- lib/uorm/redis/persistance.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
-
#model ⇒ Object
Returns the value of attribute model.
Instance Method Summary collapse
- #all(q = {}) ⇒ Object
- #create(object) ⇒ Object
- #delete(object) ⇒ Object
- #find(id) ⇒ Object
- #update(object) ⇒ Object
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client
3 4 5 |
# File 'lib/uorm/redis/persistance.rb', line 3 def client @client end |
#model ⇒ Object
Returns the value of attribute model
3 4 5 |
# File 'lib/uorm/redis/persistance.rb', line 3 def model @model end |
Instance Method Details
#all(q = {}) ⇒ Object
5 6 7 8 9 10 11 12 |
# File 'lib/uorm/redis/persistance.rb', line 5 def all q = {} arr = client.keys.map { |id| self.find id } return arr if q.empty? or arr.empty? if have_query?(q, arr) arr.select! { |attrs| q.all? { |(key, value)| [key] == value } } end end |
#create(object) ⇒ Object
18 19 20 21 |
# File 'lib/uorm/redis/persistance.rb', line 18 def create object object.id = ::SecureRandom.uuid write object end |
#delete(object) ⇒ Object
27 28 29 |
# File 'lib/uorm/redis/persistance.rb', line 27 def delete object client.del object.id end |
#find(id) ⇒ Object
14 15 16 |
# File 'lib/uorm/redis/persistance.rb', line 14 def find id client.mapped_hmget id, *model.fields.map(&:name) end |
#update(object) ⇒ Object
23 24 25 |
# File 'lib/uorm/redis/persistance.rb', line 23 def update object write object end |