Class: Flamingo::StreamParams

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/flamingo/stream_params.rb

Overview

Facade for redis: database object that behaves like a hash

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(stream_name) ⇒ StreamParams

Returns a new instance of StreamParams.



10
11
12
# File 'lib/flamingo/stream_params.rb', line 10

def initialize(stream_name)
  self.stream_name = stream_name
end

Instance Attribute Details

#stream_nameObject

Returns the value of attribute stream_name.



8
9
10
# File 'lib/flamingo/stream_params.rb', line 8

def stream_name
  @stream_name
end

Instance Method Details

#[]=(key, values) ⇒ Object



19
20
21
22
# File 'lib/flamingo/stream_params.rb', line 19

def []=(key,values)
  values = [values] unless values.is_a?(Array)
  set(key,*values)
end

#add(key, *values) ⇒ Object



24
25
26
27
28
# File 'lib/flamingo/stream_params.rb', line 24

def add(key,*values)
  values.each do |value|
    Flamingo.redis.sadd redis_key(key), value
  end
end

#allObject



51
52
53
54
55
56
# File 'lib/flamingo/stream_params.rb', line 51

def all
  keys.inject({}) do |h,key|
    h[key] = get(key)
    h
  end
end

#delete(key) ⇒ Object



36
37
38
# File 'lib/flamingo/stream_params.rb', line 36

def delete(key)
  Flamingo.redis.del redis_key(key)
end

#eachObject



58
59
60
61
62
# File 'lib/flamingo/stream_params.rb', line 58

def each
  keys.each do |key|
    yield(key,get(key))
  end
end

#get(key) ⇒ Object Also known as: []



40
41
42
# File 'lib/flamingo/stream_params.rb', line 40

def get(key)
  Flamingo.redis.smembers redis_key(key)
end

#keysObject



45
46
47
48
49
# File 'lib/flamingo/stream_params.rb', line 45

def keys
  Flamingo.redis.keys(redis_key_pattern).map do |key|
    key.split("?")[1].to_sym
  end
end

#remove(key, *values) ⇒ Object



30
31
32
33
34
# File 'lib/flamingo/stream_params.rb', line 30

def remove(key,*values)
  values.each do |value|
    Flamingo.redis.srem redis_key(key), value
  end
end

#set(key, *values) ⇒ Object



14
15
16
17
# File 'lib/flamingo/stream_params.rb', line 14

def set(key,*values)
  delete(key)
  add(key,*values)
end