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::AS_ACCESSOR, Abstract::DEFAULT_RAW_BEHAVIOR, Abstract::EMPTY_PREFIX
Instance Method Summary collapse
-
#import!(settings_interface = Module.new) ⇒ void
private
rubocop:disable Metrics/AbcSize rubocop:disable Metrics/MethodLength rubocop:disable Metrics/BlockLength rubocop:disable Metrics/PerceivedComplexity.
- #initialize(seeded_klass, imported_config, mappings: EMPTY_MAPPINGS, prefix: EMPTY_PREFIX, raw: DEFAULT_RAW_BEHAVIOR, accessor: AS_ACCESSOR) ⇒ void constructor private
Constructor Details
#initialize(seeded_klass, imported_config, mappings: EMPTY_MAPPINGS, prefix: EMPTY_PREFIX, raw: DEFAULT_RAW_BEHAVIOR, accessor: AS_ACCESSOR) ⇒ 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.
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/qonfig/imports/mappings.rb', line 23 def initialize( seeded_klass, imported_config, mappings: EMPTY_MAPPINGS, prefix: EMPTY_PREFIX, raw: DEFAULT_RAW_BEHAVIOR, accessor: AS_ACCESSOR ) prevent_incompatible_import_params!(imported_config, prefix, mappings) super(seeded_klass, imported_config, prefix: prefix, raw: raw, accessor: accessor) @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.
rubocop:disable Metrics/AbcSize rubocop:disable Metrics/MethodLength rubocop:disable Metrics/BlockLength rubocop:disable Metrics/PerceivedComplexity
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/qonfig/imports/mappings.rb', line 47 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 || key_matcher.generic?) 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, accessor ) do |raw, imported_config, accessor| 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 define_method("#{mapped_method_name}?") do # NOTE: based on Qonfig::Settings#__define_option_predicate__ realization !!imported_config[setting_key] end if accessor define_method("#{mapped_method_name}=") do |value| imported_config[setting_key] = value end end end end end end |