Sha256: 1c30cb60ddac72bc9cbbea79e77feb9cb8129f896421a0c90d29e7c605e8da4d

Contents?: true

Size: 1020 Bytes

Versions: 2

Compression:

Stored size: 1020 Bytes

Contents

# frozen_string_literal: true

# @api private
# @since 0.1.0
class Qonfig::Commands::AddNestedOption < Qonfig::Commands::Base
  # @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 settings [Qonfig::Settings]
  # @return [void]
  #
  # @api private
  # @since 0.1.0
  def call(settings)
    nested_settings = nested_data_set_klass.new.settings

    settings.__define_setting__(key, nested_settings)
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
qonfig-0.12.0 lib/qonfig/commands/add_nested_option.rb
qonfig-0.11.0 lib/qonfig/commands/add_nested_option.rb