Class: Qonfig::Imports::DirectKey Private
- Defined in:
- lib/qonfig/imports/direct_key.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.
Constant Summary
Constants inherited from Abstract
Abstract::DEFAULT_RAW_BEHAVIOR, Abstract::EMPTY_PREFIX
Instance Method Summary collapse
- #import!(settings_interface = Module.new) ⇒ void private
- #initialize(seeded_klass, imported_config, *keys, prefix: EMPTY_PREFIX, raw: DEFAULT_RAW_BEHAVIOR) ⇒ void constructor private
Constructor Details
#initialize(seeded_klass, imported_config, *keys, prefix: EMPTY_PREFIX, raw: DEFAULT_RAW_BEHAVIOR) ⇒ 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.
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/qonfig/imports/direct_key.rb', line 15 def initialize( seeded_klass, imported_config, *keys, prefix: EMPTY_PREFIX, raw: DEFAULT_RAW_BEHAVIOR ) prevent_incompatible_import_params!(imported_config, prefix, keys) super(seeded_klass, imported_config, prefix: prefix, raw: raw) @keys = keys @key_matchers = build_setting_key_matchers(keys) end |
Instance Method Details
#import!(settings_interface = Module.new) ⇒ 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.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/qonfig/imports/direct_key.rb', line 33 def import!(settings_interface = Module.new) # rubocop:disable Metrics/AbcSize key_matchers.each do |key_matcher| raise( Qonfig::UnknownSettingError, "Setting with <#{key_matcher.scope_pattern}> key does not exist!" ) unless (imported_config.keys(all_variants: true).any? do |setting_key| key_matcher.match?(setting_key) end) imported_config.keys(all_variants: true).each do |setting_key| next unless key_matcher.match?(setting_key) setting_key_path_sequence = setting_key.split('.') access_method_name = setting_key_path_sequence.last access_method_name = "#{prefix}#{access_method_name}" unless prefix.empty? settings_interface.module_exec(raw, imported_config) do |raw, imported_config| unless raw # NOTE: get setting value via slice_value define_method(access_method_name) do imported_config.slice_value(*setting_key_path_sequence) end else # NOTE: get setting object (concrete value or Qonfig::Settings object) define_method(access_method_name) do imported_config.dig(*setting_key_path_sequence) end end end end end end |