Sha256: cb79cd8934c859dbf5a8a2c3ca2bc711ba98457fcd1c6e5df16fc31eb437b562

Contents?: true

Size: 1.48 KB

Versions: 1

Compression:

Stored size: 1.48 KB

Contents

# frozen_string_literal: true

module Qonfig
  # @api private
  # @since 0.1.0
  module DSL
    class << self
      # @param child_klass [Qonfig::DataSet]
      # @return [void]
      #
      # @api private
      # @since 0.1.0
      def extended(child_klass)
        child_klass.instance_variable_set(:@commands, Qonfig::CommandSet.new)

        class << child_klass
          def inherited(child_klass)
            child_klass.instance_variable_set(:@commands, Qonfig::CommandSet.new)
            child_klass.commands.concat(commands)
          end
        end
      end
    end

    # @return [Qonfig::CommandSet]
    #
    # @api private
    # @since 0.1.0
    def commands
      @commands
    end

    # @param key [String,Symbol]
    # @param initial_value [Object]
    # @param nested_settings [Proc]
    # @return [void]
    #
    # @api public
    # @since 0.1.0
    def setting(key, initial_value = nil, &nested_settings)
      unless key.is_a?(Symbol) || key.is_a?(String)
        raise Qonfig::ArgumentError, 'Setting key should be a symbol or a string!'
      end

      if block_given?
        commands << Qonfig::Commands::AddNestedOption.new(key, nested_settings)
      else
        commands << Qonfig::Commands::AddOption.new(key, initial_value)
      end
    end

    # @param data_set_klass [Class{Qonfig::DataSet}]
    # @return [void]
    #
    # @api private
    # @sine 0.1.0
    def compose(data_set_klass)
      commands << Qonfig::Commands::Compose.new(data_set_klass)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
qonfig-0.1.0 lib/qonfig/dsl.rb