Class: Ez::Settings::Backend::Redis
- Inherits:
-
Object
- Object
- Ez::Settings::Backend::Redis
- Defined in:
- lib/ez/settings/backend/redis.rb
Constant Summary collapse
- PREFIX =
'ez:settings'
- NAMESPACE =
'config'
Instance Attribute Summary collapse
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
-
#namespace ⇒ Object
readonly
Returns the value of attribute namespace.
Instance Method Summary collapse
-
#initialize(connection, namespace: NAMESPACE) ⇒ Redis
constructor
A new instance of Redis.
- #read ⇒ Object
- #write(data) ⇒ Object
Constructor Details
Instance Attribute Details
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
12 13 14 |
# File 'lib/ez/settings/backend/redis.rb', line 12 def connection @connection end |
#namespace ⇒ Object (readonly)
Returns the value of attribute namespace.
12 13 14 |
# File 'lib/ez/settings/backend/redis.rb', line 12 def namespace @namespace end |
Instance Method Details
#read ⇒ Object
19 20 21 22 |
# File 'lib/ez/settings/backend/redis.rb', line 19 def read value = connection.get(key) value.nil? ? {} : JSON.parse(value).deep_symbolize_keys end |
#write(data) ⇒ Object
24 25 26 27 |
# File 'lib/ez/settings/backend/redis.rb', line 24 def write(data) new_data = read.merge(data) connection.set(key, JSON.generate(new_data)) end |