Module: Enum::RedisStore::Getter

Defined in:
lib/enum/store/redis_store.rb

Overview

> Setter

Class Method Summary collapse

Class Method Details

.get_hash_value(connection, key) ⇒ Object



115
116
117
118
119
120
121
# File 'lib/enum/store/redis_store.rb', line 115

def get_hash_value(connection, key)
  connection.hgetall(key).inject(Hash.new) do |out, pair|
    k, v = pair
    out[k] = is_enum_key?(v) ? get_value(connection, v[9..-1]) : v
    out
  end
end

.get_list_value(connection, key) ⇒ Object



109
110
111
112
113
# File 'lib/enum/store/redis_store.rb', line 109

def get_list_value(connection, key)
  connection.lrange(key, 0, -1).map do |value|
    is_enum_key?(value) ? get_value(connection, value[9..-1]) : value
  end
end

.get_string_value(connection, key) ⇒ Object



105
106
107
# File 'lib/enum/store/redis_store.rb', line 105

def get_string_value(connection, key)
  connection.get(key)
end

.get_value(connection, key) ⇒ Object



95
96
97
98
99
100
101
102
103
# File 'lib/enum/store/redis_store.rb', line 95

def get_value(connection, key)
  raise_unknown_key(key) unless connection.exists(key)

  meth = :"get_#{connection.type(key)}_value"

  raise_unknown_value_type(meth, key) unless self.respond_to?(meth)

  send(meth, connection, key)
end

.is_enum_key?(key) ⇒ Boolean

Returns:

  • (Boolean)


123
124
125
# File 'lib/enum/store/redis_store.rb', line 123

def is_enum_key?(key)
  !/ENUM_KEY:.*/.match(key.to_s).nil?
end

.raise_unknown_key(key) ⇒ Object

Raises:

  • (ArgumentError)


131
132
133
# File 'lib/enum/store/redis_store.rb', line 131

def raise_unknown_key(key)
  raise ArgumentError.new("Enum [ #{key} ] is not defined.")
end

.raise_unknown_value_type(meth, key) ⇒ Object



127
128
129
# File 'lib/enum/store/redis_store.rb', line 127

def raise_unknown_value_type(meth, key)
  raise "#{key} has unknown value type: #{meth} is not defined."
end