Class: Flamingo::Meta

Inherits:
Object
  • Object
show all
Defined in:
lib/flamingo/meta.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#redisObject

Returns the value of attribute redis.



5
6
7
# File 'lib/flamingo/meta.rb', line 5

def redis
  @redis
end

Instance Method Details

#allObject



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

#clearObject



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_hObject



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