Class: Qonfig::Imports::Mappings Private
- Defined in:
- lib/qonfig/imports/mappings.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 collapse
- EMPTY_MAPPINGS =
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.
{}.freeze
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, mappings: EMPTY_MAPPINGS, prefix: EMPTY_PREFIX, raw: DEFAULT_RAW_BEHAVIOR) ⇒ void constructor private
Constructor Details
#initialize(seeded_klass, imported_config, mappings: EMPTY_MAPPINGS, 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.
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/qonfig/imports/mappings.rb', line 21 def initialize( seeded_klass, imported_config, mappings: EMPTY_MAPPINGS, prefix: EMPTY_PREFIX, raw: DEFAULT_RAW_BEHAVIOR ) prevent_incompatible_import_params!(imported_config, prefix, mappings) super(seeded_klass, imported_config, prefix: prefix, raw: raw) @mappings = mappings @key_matchers = build_setting_key_matchers(mappings) 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.
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 65 66 67 68 69 |
# File 'lib/qonfig/imports/mappings.rb', line 39 def import!(settings_interface = Module.new) # rubocop:disable Metrics/AbcSize key_matchers.each_pair do |(mapped_method_name, 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('.') mapped_method_name = "#{prefix}#{mapped_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(mapped_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(mapped_method_name) do imported_config.dig(*setting_key_path_sequence) end end end end end end |