Class: Flamingo::Meta
- Inherits:
-
Object
- Object
- Flamingo::Meta
- Defined in:
- lib/flamingo/meta.rb
Instance Attribute Summary collapse
-
#redis ⇒ Object
Returns the value of attribute redis.
Instance Method Summary collapse
- #all ⇒ Object
- #clear ⇒ Object
- #delete(name) ⇒ Object
- #get(name) ⇒ Object (also: #[])
- #incr(name, amt = 1) ⇒ Object
-
#initialize(redis) ⇒ Meta
constructor
A new instance of Meta.
- #set(name, value) ⇒ Object (also: #[]=)
- #to_h ⇒ Object
Constructor Details
#initialize(redis) ⇒ Meta
Returns a new instance of Meta.
7 8 9 |
# File 'lib/flamingo/meta.rb', line 7 def initialize(redis) self.redis = redis end |
Instance Attribute Details
#redis ⇒ Object
Returns the value of attribute redis.
5 6 7 |
# File 'lib/flamingo/meta.rb', line 5 def redis @redis end |
Instance Method Details
#all ⇒ Object
29 30 31 32 33 |
# File 'lib/flamingo/meta.rb', line 29 def all redis.keys("#{namespace}*").map do |k| [denamespace(k),norm_value(redis.get(k))] end end |
#clear ⇒ Object
35 36 37 38 39 |
# File 'lib/flamingo/meta.rb', line 35 def clear all.each do |key,value| delete(key) end end |
#delete(name) ⇒ Object
25 26 27 |
# File 'lib/flamingo/meta.rb', line 25 def delete(name) redis.del(key(name)) end |
#get(name) ⇒ Object Also known as: []
20 21 22 |
# File 'lib/flamingo/meta.rb', line 20 def get(name) norm_value(redis.get(key(name))) end |
#incr(name, amt = 1) ⇒ Object
11 12 13 |
# File 'lib/flamingo/meta.rb', line 11 def incr(name,amt=1) redis.incrby(key(name),amt) end |
#set(name, value) ⇒ Object Also known as: []=
15 16 17 |
# File 'lib/flamingo/meta.rb', line 15 def set(name,value) redis.set(key(name),value) end |
#to_h ⇒ Object
41 42 43 44 45 46 |
# File 'lib/flamingo/meta.rb', line 41 def to_h all.inject({}) do |hash, (key,value)| hash[key] = value hash end end |