Class: Retained::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/retained/configuration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

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_groupObject (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_configsObject (readonly)

Returns the value of attribute group_configs.



9
10
11
# File 'lib/retained/configuration.rb', line 9

def group_configs
  @group_configs
end

#prefixObject

Returns the value of attribute prefix.



7
8
9
# File 'lib/retained/configuration.rb', line 7

def prefix
  @prefix
end

#redisObject

Returns the value of attribute redis.



6
7
8
# File 'lib/retained/configuration.rb', line 6

def redis
  @redis
end

#redis_connectionObject



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