Class: Qonfig::Settings Private
- Inherits:
-
Object
- Object
- Qonfig::Settings
- Defined in:
- lib/qonfig/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.
rubocop:disable Metrics/ClassLength, Layout/ClassStructure
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
Instance Attribute Summary collapse
- #__mutation_callbacks__ ⇒ Qonfig::Settings::Callbacks readonly private
- #__options__ ⇒ Hash readonly private
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ void
- #__append_settings__(settings) ⇒ void private
- #__apply_values__(settings_map) ⇒ void private
- #__clear__ ⇒ void private
- #__deep_each_setting__(initial_setting_key = nil, &block) {|key, value| ... } ⇒ Enumerable private
- #__define_setting__(key, value) ⇒ void private
- #__dig__(*keys) ⇒ Object private
- #__each_setting__(&block) {|key, value| ... } ⇒ Enumerable private
- #__freeze__ ⇒ void private
- #__invoke_mutation_callbacks__ ⇒ void private
- #__is_a_setting__(value) ⇒ Boolean private
- #__is_frozen__ ⇒ Boolean private
- #__slice__(*keys) ⇒ Hash private
- #__slice_value__(*keys) ⇒ Hash, Any private
- #__subset__(*keys) ⇒ Hash private
-
#__to_hash__(transform_key: BASIC_SETTING_KEY_TRANSFORMER, transform_value: BASIC_SETTING_VALUE_TRANSFORMER) ⇒ Hash
(also: #__to_h__)
private
rubocop:disable Metrics/LineLength.
-
#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
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.
39 40 41 42 43 |
# File 'lib/qonfig/settings.rb', line 39 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.
228 229 230 231 232 |
# File 'lib/qonfig/settings.rb', line 228 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.
35 36 37 |
# File 'lib/qonfig/settings.rb', line 35 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.
29 30 31 |
# File 'lib/qonfig/settings.rb', line 29 def @__options__ end |
Instance Method Details
#[](key) ⇒ Object
129 130 131 |
# File 'lib/qonfig/settings.rb', line 129 def [](key) __lock__.thread_safe_access { __get_value__(key) } end |
#[]=(key, value) ⇒ void
This method returns an undefined value.
139 140 141 |
# File 'lib/qonfig/settings.rb', line 139 def []=(key, value) __lock__.thread_safe_access { __set_value__(key, value) } end |
#__append_settings__(settings) ⇒ 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.
108 109 110 111 112 113 114 |
# File 'lib/qonfig/settings.rb', line 108 def __append_settings__(settings) __lock__.thread_safe_merge do settings..each_pair do |key, value| __define_setting__(key, value) 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.
148 149 150 |
# File 'lib/qonfig/settings.rb', line 148 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.
215 216 217 |
# File 'lib/qonfig/settings.rb', line 215 def __clear__ __lock__.thread_safe_access { __clear_option_values__ } end |
#__deep_each_setting__(initial_setting_key = nil, &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.
70 71 72 73 74 |
# File 'lib/qonfig/settings.rb', line 70 def __deep_each_setting__(initial_setting_key = nil, &block) __lock__.thread_safe_access do __deep_each_key_value_pair__(initial_setting_key, &block) end end |
#__define_setting__(key, value) ⇒ 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.
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/qonfig/settings.rb', line 82 def __define_setting__(key, value) # rubocop:disable Metrics/AbcSize __lock__.thread_safe_definition do key = __indifferently_accessable_option_key__(key) __prevent_core_method_intersection__(key) case when !.key?(key) [key] = value when __is_a_setting__([key]) && __is_a_setting__(value) [key].__append_settings__(value) else [key] = value end __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.
157 158 159 |
# File 'lib/qonfig/settings.rb', line 157 def __dig__(*keys) __lock__.thread_safe_access { __deep_access__(*keys) } 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.
54 55 56 57 58 |
# File 'lib/qonfig/settings.rb', line 54 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.
248 249 250 251 252 253 254 255 256 |
# File 'lib/qonfig/settings.rb', line 248 def __freeze__ __lock__.thread_safe_access do .freeze .each_value do |value| value.__freeze__ if __is_a_setting__(value) end end 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.
120 121 122 |
# File 'lib/qonfig/settings.rb', line 120 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.
271 272 273 |
# File 'lib/qonfig/settings.rb', line 271 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.
262 263 264 |
# File 'lib/qonfig/settings.rb', line 262 def __is_frozen__ __lock__.thread_safe_access { .frozen? } 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.
166 167 168 |
# File 'lib/qonfig/settings.rb', line 166 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.
175 176 177 |
# File 'lib/qonfig/settings.rb', line 175 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.
184 185 186 |
# File 'lib/qonfig/settings.rb', line 184 def __subset__(*keys) __lock__.thread_safe_access { __deep_subset__(*keys) } end |
#__to_hash__(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.
rubocop:disable Metrics/LineLength
195 196 197 198 199 200 201 202 203 204 205 206 207 |
# File 'lib/qonfig/settings.rb', line 195 def __to_hash__(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 proc') end unless transform_value.is_a?(Proc) ::Kernel.raise(Qonfig::IncorrectValueTransformerError, 'Value transformer should be a proc') end __lock__.thread_safe_access do __build_hash_representation__(transform_key: transform_key, transform_value: transform_value) 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.
238 239 240 241 242 |
# File 'lib/qonfig/settings.rb', line 238 def respond_to_missing?(method_name, include_private = false) # :nocov: .key?(method_name.to_s) || .key?(method_name.to_sym) || super # :nocov: end |