Class: Qonfig::Settings Private
- Inherits:
-
Object
- Object
- Qonfig::Settings
- Includes:
- Plugins::PrettyPrint::SettingsMixin
- Defined in:
- lib/qonfig/settings.rb,
lib/qonfig/plugins/pretty_print/settings.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.
Defined Under Namespace
Modules: Builder Classes: Callbacks, KeyGuard, KeyMatcher, Lock
Constant Summary collapse
- BASIC_SETTING_KEY_TRANSFORMER =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
(proc { |value| value }).freeze
- BASIC_SETTING_VALUE_TRANSFORMER =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
(proc { |value| value }).freeze
- REPRESENT_HASH_IN_DOT_STYLE =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
false- DOT_NOTATION_SEPARATOR =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
'.'
Instance Attribute Summary collapse
- #__mutation_callbacks__ ⇒ Qonfig::Settings::Callbacks readonly private
- #__options__ ⇒ Hash readonly private
Instance Method Summary collapse
- #[](*keys) ⇒ Object
- #[]=(key, value) ⇒ void
- #__append_settings__(settings, with_redefinition: false) ⇒ void private
- #__apply_values__(settings_map) ⇒ void private
- #__clear__ ⇒ void private
- #__deep_each_setting__(initial_setting_key = nil, yield_all: false, &block) {|key, value| ... } ⇒ Enumerable private
- #__define_setting__(key, value, with_redefinition: false) ⇒ void private
- #__dig__(*keys) ⇒ Object private
- #__each_setting__(&block) {|key, value| ... } ⇒ Enumerable private
- #__freeze__ ⇒ void private
- #__has_key__(*key_path) ⇒ Boolean private
- #__invoke_mutation_callbacks__ ⇒ void private
- #__is_a_setting__(value) ⇒ Boolean private
- #__is_frozen__ ⇒ Boolean private
- #__keys__(all_variants: false) ⇒ Array<String> private
- #__root_keys__ ⇒ Array<String> private
- #__slice__(*keys) ⇒ Hash private
- #__slice_value__(*keys) ⇒ Hash, Any private
- #__subset__(*keys) ⇒ Hash private
- #__to_hash__(dot_notation: REPRESENT_HASH_IN_DOT_STYLE, transform_key: BASIC_SETTING_KEY_TRANSFORMER, transform_value: BASIC_SETTING_VALUE_TRANSFORMER) ⇒ Hash (also: #__to_h__) private
-
#initialize(__mutation_callbacks__) ⇒ Settings
constructor
private
A new instance of Settings.
- #method_missing(method_name, *arguments, &block) ⇒ void private
- #respond_to_missing?(method_name, include_private = false) ⇒ Boolean private
Methods included from Plugins::PrettyPrint::SettingsMixin
Constructor Details
#initialize(__mutation_callbacks__) ⇒ Settings
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 a new instance of Settings.
51 52 53 54 55 |
# File 'lib/qonfig/settings.rb', line 51 def initialize(__mutation_callbacks__) @__options__ = {} @__lock__ = Lock.new @__mutation_callbacks__ = __mutation_callbacks__ end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *arguments, &block) ⇒ 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.
298 299 300 301 302 |
# File 'lib/qonfig/settings.rb', line 298 def method_missing(method_name, *arguments, &block) super rescue NoMethodError ::Kernel.raise(Qonfig::UnknownSettingError, "Setting with <#{method_name}> key doesnt exist!") end |
Instance Attribute Details
#__mutation_callbacks__ ⇒ Qonfig::Settings::Callbacks (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.
47 48 49 |
# File 'lib/qonfig/settings.rb', line 47 def __mutation_callbacks__ @__mutation_callbacks__ end |
#__options__ ⇒ Hash (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.
41 42 43 |
# File 'lib/qonfig/settings.rb', line 41 def @__options__ end |
Instance Method Details
#[](*keys) ⇒ Object
151 152 153 |
# File 'lib/qonfig/settings.rb', line 151 def [](*keys) __dig__(*keys) end |
#[]=(key, value) ⇒ void
This method returns an undefined value.
162 163 164 |
# File 'lib/qonfig/settings.rb', line 162 def []=(key, value) __lock__.thread_safe_access { __assign_value__(key, value) } end |
#__append_settings__(settings, with_redefinition: false) ⇒ 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.
127 128 129 130 131 132 133 |
# File 'lib/qonfig/settings.rb', line 127 def __append_settings__(settings, with_redefinition: false) __lock__.thread_safe_merge do settings..each_pair do |key, value| __define_setting__(key, value, with_redefinition: with_redefinition) end end end |
#__apply_values__(settings_map) ⇒ 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.
171 172 173 |
# File 'lib/qonfig/settings.rb', line 171 def __apply_values__(settings_map) __lock__.thread_safe_access { __set_values_from_map__(settings_map) } end |
#__clear__ ⇒ 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.
285 286 287 |
# File 'lib/qonfig/settings.rb', line 285 def __clear__ __lock__.thread_safe_access { __clear_option_values__ } end |
#__deep_each_setting__(initial_setting_key = nil, yield_all: false, &block) {|key, value| ... } ⇒ Enumerable
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.
83 84 85 86 87 |
# File 'lib/qonfig/settings.rb', line 83 def __deep_each_setting__(initial_setting_key = nil, yield_all: false, &block) __lock__.thread_safe_access do __deep_each_key_value_pair__(initial_setting_key, yield_all: yield_all, &block) end end |
#__define_setting__(key, value, with_redefinition: false) ⇒ 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.
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/qonfig/settings.rb', line 97 def __define_setting__(key, value, with_redefinition: false) # rubocop:disable Metrics/AbcSize __lock__.thread_safe_definition do key = __indifferently_accessable_option_key__(key) __prevent_core_method_intersection__(key) # rubocop:disable Lint/DuplicateBranch case when with_redefinition || !.key?(key) [key] = value when __is_a_setting__([key]) && __is_a_setting__(value) [key].__append_settings__(value) else [key] = value end # rubocop:enable Lint/DuplicateBranch __define_option_reader__(key) __define_option_writer__(key) __define_option_predicate__(key) end end |
#__dig__(*keys) ⇒ Object
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.
180 181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/qonfig/settings.rb', line 180 def __dig__(*keys) __lock__.thread_safe_access do begin __deep_access__(*keys) rescue Qonfig::UnknownSettingError if keys.size == 1 __deep_access__(*__parse_dot_notated_key__(keys.first)) else raise end end end end |
#__each_setting__(&block) {|key, value| ... } ⇒ Enumerable
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.
66 67 68 69 70 |
# File 'lib/qonfig/settings.rb', line 66 def __each_setting__(&block) __lock__.thread_safe_access do __each_key_value_pair__(&block) end end |
#__freeze__ ⇒ 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.
318 319 320 321 322 323 324 325 326 |
# File 'lib/qonfig/settings.rb', line 318 def __freeze__ __lock__.thread_safe_access do .freeze .each_value do |value| value.__freeze__ if __is_a_setting__(value) end end end |
#__has_key__(*key_path) ⇒ Boolean
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.
350 351 352 |
# File 'lib/qonfig/settings.rb', line 350 def __has_key__(*key_path) __lock__.thread_safe_access { __is_key_exists__(*key_path) } end |
#__invoke_mutation_callbacks__ ⇒ 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.
139 140 141 |
# File 'lib/qonfig/settings.rb', line 139 def __invoke_mutation_callbacks__ __mutation_callbacks__.call end |
#__is_a_setting__(value) ⇒ Boolean
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.
341 342 343 |
# File 'lib/qonfig/settings.rb', line 341 def __is_a_setting__(value) value.is_a?(Qonfig::Settings) end |
#__is_frozen__ ⇒ Boolean
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.
332 333 334 |
# File 'lib/qonfig/settings.rb', line 332 def __is_frozen__ __lock__.thread_safe_access { .frozen? } end |
#__keys__(all_variants: false) ⇒ Array<String>
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.
269 270 271 |
# File 'lib/qonfig/settings.rb', line 269 def __keys__(all_variants: false) __lock__.thread_safe_access { __setting_keys__(all_variants: all_variants) } end |
#__root_keys__ ⇒ Array<String>
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.
277 278 279 |
# File 'lib/qonfig/settings.rb', line 277 def __root_keys__ __lock__.thread_safe_access { __root_setting_keys__ } end |
#__slice__(*keys) ⇒ Hash
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.
199 200 201 |
# File 'lib/qonfig/settings.rb', line 199 def __slice__(*keys) __lock__.thread_safe_access { __deep_slice__(*keys) } end |
#__slice_value__(*keys) ⇒ Hash, Any
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.
208 209 210 |
# File 'lib/qonfig/settings.rb', line 208 def __slice_value__(*keys) __lock__.thread_safe_access { __deep_slice_value__(*keys) } end |
#__subset__(*keys) ⇒ Hash
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.
217 218 219 |
# File 'lib/qonfig/settings.rb', line 217 def __subset__(*keys) __lock__.thread_safe_access { __deep_subset__(*keys) } end |
#__to_hash__(dot_notation: REPRESENT_HASH_IN_DOT_STYLE, transform_key: BASIC_SETTING_KEY_TRANSFORMER, transform_value: BASIC_SETTING_VALUE_TRANSFORMER) ⇒ Hash Also known as: __to_h__
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.
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 |
# File 'lib/qonfig/settings.rb', line 229 def __to_hash__( dot_notation: REPRESENT_HASH_IN_DOT_STYLE, transform_key: BASIC_SETTING_KEY_TRANSFORMER, transform_value: BASIC_SETTING_VALUE_TRANSFORMER ) unless transform_key.is_a?(Proc) ::Kernel.raise( Qonfig::IncorrectKeyTransformerError, 'Key transformer should be a type of proc' ) end unless transform_value.is_a?(Proc) ::Kernel.raise( Qonfig::IncorrectValueTransformerError, 'Value transformer should be a type of proc' ) end __lock__.thread_safe_access do if dot_notation __build_dot_notated_hash_representation__( transform_key: transform_key, transform_value: transform_value ) else __build_basic_hash_representation__( transform_key: transform_key, transform_value: transform_value ) end end end |
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
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.
308 309 310 311 312 |
# File 'lib/qonfig/settings.rb', line 308 def respond_to_missing?(method_name, include_private = false) # :nocov: .key?(method_name.to_s) || .key?(method_name.to_sym) || super # :nocov: end |