Class: RedisQueuedLocks::Config Private

Inherits:
Object
  • Object
show all
Includes:
DSL
Defined in:
lib/redis_queued_locks/config.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

rubocop:disable Metrics/ClassLength

Since:

  • 1.13.0

Version:

  • 1.15.1

Defined Under Namespace

Modules: DSL

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from DSL

included

Constructor Details

#initialize(&configuration) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 1.13.0



125
126
127
128
129
# File 'lib/redis_queued_locks/config.rb', line 125

def initialize(&configuration)
  @config_state = {}
  config_setters.each_value { |setter| setter.call(@config_state) }
  configure(&configuration)
end

Instance Attribute Details

#config_state ⇒ Hash<Symbol,Any> (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Hash<Symbol,Any>)

Since:

  • 1.13.0



119
120
121
# File 'lib/redis_queued_locks/config.rb', line 119

def config_state
  @config_state
end

Instance Method Details

#[](config_key) ⇒ Any

Parameters:

  • config_key (String)

Returns:

  • (Any)

Raises:

Since:

  • 1.13.0



149
150
151
152
# File 'lib/redis_queued_locks/config.rb', line 149

def [](config_key)
  prevent_key__non_existent(config_key)
  config_state[config_key]
end

#[]=(config_key, config_value) ⇒ void

This method returns an undefined value.

Parameters:

  • config_key (String)
  • config_value (Any)

Raises:

Since:

  • 1.13.0



163
164
165
166
167
# File 'lib/redis_queued_locks/config.rb', line 163

def []=(config_key, config_value)
  prevent_key__non_existent(config_key)
  prevent_key__invalid_type(config_key, config_value)
  config_state[config_key] = config_value
end

#configure(&configuration) {|?| ... } ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Parameters:

  • configuration (Block)

Yields:

  • (?)

Yield Parameters:

  • (?)

Since:

  • 1.13.0



138
139
140
# File 'lib/redis_queued_locks/config.rb', line 138

def configure(&configuration)
  yield(self) if block_given?
end

#slice(config_key_pattern) ⇒ Hash<String,Any>

Returns the slice of the config values as a hash match the received pattern. Matched configs will be sliced as a nested config (as a hash object). And config valuess will be duplicated via Object#dup. How it works:

initial config sate: => {
'swarm.flush_zombies.redis_config.pooled' => true,
'swarm.flush_zombies.redis_config.sentinel' => true,
'swarm.aut_swarm' => false,
'logger' => Logger.new
}
slice with "swarm.flush_zombies.redis_config" pattern: => {
'pooled' => true,
'sentinel' => true
}

Parameters:

  • config_key_pattern (String)

Returns:

  • (Hash<String,Any>)

Since:

  • 1.13.0



188
189
190
191
192
193
194
195
196
197
198
199
200
# File 'lib/redis_queued_locks/config.rb', line 188

def slice(config_key_pattern)
  key_selector = "#{config_key_pattern}."
  key_splitter = key_selector.size
  sliced_config = {} #: Hash[String,untyped]

  config_state.each_pair do |config_key, config_value|
    next unless config_key.start_with?(key_selector)
    sliced_config_key = config_key[key_splitter..] #: String
    sliced_config[sliced_config_key] = config_value.dup
  end

  sliced_config
end