Class: Redis::Settings
- Inherits:
-
Object
- Object
- Redis::Settings
- Defined in:
- lib/redis/settings.rb,
lib/redis/settings/railtie.rb,
lib/redis/settings/version.rb,
lib/redis/settings/active_record.rb
Defined Under Namespace
Modules: ActiveRecord, Version Classes: NewRecordError, Railtie
Class Attribute Summary collapse
-
.connection ⇒ Object
Returns the value of attribute connection.
-
.root_namespace ⇒ Object
Returns the value of attribute root_namespace.
Class Method Summary collapse
-
.configure {|_self| ... } ⇒ Object
Return Redis::Settings.
Instance Method Summary collapse
-
#all ⇒ Object
Return a hash with all settings.
-
#clear ⇒ Object
Remove all settings from the current namespace.
-
#get(name, default = nil) ⇒ Object
(also: #[], #fetch)
Retrieve setting by its name.
-
#initialize(namespace) ⇒ Settings
constructor
Initialize a new object that will be wrapped into the specified namespace.
-
#namespace ⇒ Object
Return instance’s namespace concatenated with Redis::Settings.root_namespace.
-
#remove(name) ⇒ Object
(also: #delete)
Delete the specified option.
-
#set(name, value) ⇒ Object
(also: #[]=)
Define a value for the specified setting.
Constructor Details
Class Attribute Details
.connection ⇒ Object
Returns the value of attribute connection.
19 20 21 |
# File 'lib/redis/settings.rb', line 19 def connection @connection end |
.root_namespace ⇒ Object
Returns the value of attribute root_namespace.
20 21 22 |
# File 'lib/redis/settings.rb', line 20 def root_namespace @root_namespace end |
Class Method Details
Instance Method Details
#all ⇒ Object
Return a hash with all settings
99 100 101 |
# File 'lib/redis/settings.rb', line 99 def all Hash[redis.hgetall(namespace).collect {|k, v| [k.to_sym, JSON.parse(v)["data"]]}] end |
#clear ⇒ Object
Remove all settings from the current namespace
94 95 96 |
# File 'lib/redis/settings.rb', line 94 def clear redis.del(namespace) end |
#get(name, default = nil) ⇒ Object Also known as: [], fetch
61 62 63 64 65 66 67 68 69 70 |
# File 'lib/redis/settings.rb', line 61 def get(name, default = nil) value = redis.hget(namespace, name) if value payload = JSON.parse(value) value = payload["data"] end value.nil? ? default : value end |
#namespace ⇒ Object
51 52 53 |
# File 'lib/redis/settings.rb', line 51 def namespace "#{self.class.root_namespace}/#{@namespace}" end |
#remove(name) ⇒ Object Also known as: delete
Delete the specified option. Just a shortcut for settings.set(:name, nil)
.
87 88 89 |
# File 'lib/redis/settings.rb', line 87 def remove(name) set(name, nil) end |
#set(name, value) ⇒ Object Also known as: []=
77 78 79 80 81 82 83 |
# File 'lib/redis/settings.rb', line 77 def set(name, value) if value.nil? redis.hdel(namespace, name) else redis.hset(namespace, name, {:data => value}.to_json) end end |