Sha256: 572c73f3e5bf0bfb2b6363bbaac56bad60403d494c59326f2b72c4f77ba04aff

Contents?: true

Size: 1.18 KB

Versions: 12

Compression:

Stored size: 1.18 KB

Contents

# frozen_string_literal: true

# @api private
# @since 0.1.0
class Qonfig::Commands::Definition::AddNestedOption < Qonfig::Commands::Base
  # @since 0.19.0
  self.inheritable = true

  # @return [Symbol, String]
  #
  # @api private
  # @since 0.1.0
  attr_reader :key

  # @return [Class<Qonfig::DataSet>]
  #
  # @api private
  # @since 0.2.0
  attr_reader :nested_data_set_klass

  # @param key [Symbol, String]
  # @param nested_definitions [Proc]
  #
  # @raise [Qonfig::ArgumentError]
  # @raise [Qonfig::CoreMethodIntersectionError]
  #
  # @api private
  # @since 0.1.0
  def initialize(key, nested_definitions)
    Qonfig::Settings::KeyGuard.prevent_incomparabilities!(key)

    @key = key
    @nested_data_set_klass = Class.new(Qonfig::DataSet).tap do |data_set|
      data_set.instance_eval(&nested_definitions)
    end
  end

  # @param data_set [Qonfig::DataSet]
  # @param settings [Qonfig::Settings]
  # @return [void]
  #
  # @api private
  # @since 0.1.0
  def call(data_set, settings)
    nested_settings = nested_data_set_klass.new.settings

    nested_settings.__mutation_callbacks__.add(settings.__mutation_callbacks__)
    settings.__define_setting__(key, nested_settings)
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
qonfig-0.28.0 lib/qonfig/commands/definition/add_nested_option.rb
qonfig-0.27.0 lib/qonfig/commands/definition/add_nested_option.rb
qonfig-0.26.0 lib/qonfig/commands/definition/add_nested_option.rb
qonfig-0.25.0 lib/qonfig/commands/definition/add_nested_option.rb
qonfig-0.24.1 lib/qonfig/commands/definition/add_nested_option.rb
qonfig-0.24.0 lib/qonfig/commands/definition/add_nested_option.rb
qonfig-0.23.0 lib/qonfig/commands/definition/add_nested_option.rb
qonfig-0.22.0 lib/qonfig/commands/definition/add_nested_option.rb
qonfig-0.21.0 lib/qonfig/commands/definition/add_nested_option.rb
qonfig-0.20.0 lib/qonfig/commands/definition/add_nested_option.rb
qonfig-0.19.1 lib/qonfig/commands/definition/add_nested_option.rb
qonfig-0.19.0 lib/qonfig/commands/definition/add_nested_option.rb