Class: Retained::Configuration
- Inherits:
-
Object
- Object
- Retained::Configuration
- Defined in:
- lib/retained/configuration.rb
Instance Attribute Summary collapse
-
#default_group ⇒ Object
readonly
Returns the value of attribute default_group.
-
#group_configs ⇒ Object
readonly
Returns the value of attribute group_configs.
-
#prefix ⇒ Object
Returns the value of attribute prefix.
-
#redis ⇒ Object
Returns the value of attribute redis.
- #redis_connection ⇒ Object
Instance Method Summary collapse
-
#group(group) ⇒ Object
Retrieve the configuration for the group.
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
12 13 14 15 16 17 |
# File 'lib/retained/configuration.rb', line 12 def initialize @redis = { url: 'redis://localhost:6379' } @prefix = 'retained' @default_group = 'default' @group_configs = {} end |
Instance Attribute Details
#default_group ⇒ Object (readonly)
Returns the value of attribute default_group.
8 9 10 |
# File 'lib/retained/configuration.rb', line 8 def default_group @default_group end |
#group_configs ⇒ Object (readonly)
Returns the value of attribute group_configs.
9 10 11 |
# File 'lib/retained/configuration.rb', line 9 def group_configs @group_configs end |
#prefix ⇒ Object
Returns the value of attribute prefix.
7 8 9 |
# File 'lib/retained/configuration.rb', line 7 def prefix @prefix end |
#redis ⇒ Object
Returns the value of attribute redis.
6 7 8 |
# File 'lib/retained/configuration.rb', line 6 def redis @redis end |
#redis_connection ⇒ Object
34 35 36 |
# File 'lib/retained/configuration.rb', line 34 def redis_connection @redis_connection ||= RedisConnection.new(redis) end |
Instance Method Details
#group(group) ⇒ Object
Retrieve the configuration for the group. A block may be provided to configure the group.
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/retained/configuration.rb', line 21 def group(group) @group_configs[group.to_s] ||= fetch_group_configuration(group) if block_given? yield(@group_configs[group.to_s]) save_group_configuration(group, @group_configs[group.to_s]) else @group_configs[group.to_s].set_defaults end @group_configs[group.to_s] end |