Class: RedisQueuedLocks::Config Private
- Inherits:
-
Object
- Object
- RedisQueuedLocks::Config
- 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
Defined Under Namespace
Modules: DSL
Instance Attribute Summary collapse
- #config_state ⇒ Hash<Symbol,Any> readonly private
Instance Method Summary collapse
- #[](config_key) ⇒ Any
- #[]=(config_key, config_value) ⇒ void
- #configure(&configuration) {|?| ... } ⇒ void private
- #initialize(&configuration) ⇒ void constructor private
-
#slice(config_key_pattern) ⇒ Hash<String,Any>
Returns the slice of the config values as a
hashmatch the received pattern.
Methods included from DSL
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.
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.
119 120 121 |
# File 'lib/redis_queued_locks/config.rb', line 119 def config_state @config_state end |
Instance Method Details
#[](config_key) ⇒ Any
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.
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.
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
}
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 |