Sha256: b468bbbca469492f876063d9ad6384321de03048ab4ac3d0000cede13c9afdda

Contents?: true

Size: 975 Bytes

Versions: 10

Compression:

Stored size: 975 Bytes

Contents

# frozen_string_literal: true

require 'dry/configurable/setting'
require 'dry/configurable/settings'

module Dry
  module Configurable
    # Setting compiler used internally by the DSL
    #
    # @api private
    class Compiler
      def call(ast)
        Settings.new.tap do |settings|
          ast.each do |node|
            settings << visit(node)
          end
        end
      end

      # @api private
      def visit(node)
        type, rest = node
        public_send(:"visit_#{type}", rest)
      end

      # @api private
      def visit_constructor(node)
        setting, constructor = node
        visit(setting).with(constructor: constructor)
      end

      # @api private
      def visit_setting(node)
        name, default, opts = node
        Setting.new(name, **opts, default: default)
      end

      # @api private
      def visit_nested(node)
        parent, children = node
        visit(parent).nested(call(children))
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
dry-configurable-0.12.1 lib/dry/configurable/compiler.rb
dry-configurable-0.12.0 lib/dry/configurable/compiler.rb
grape-extra_validators-2.0.0 vendor/bundle/ruby/2.6.0/gems/dry-configurable-0.11.6/lib/dry/configurable/compiler.rb
dry-configurable-0.11.6 lib/dry/configurable/compiler.rb
dry-configurable-0.11.5 lib/dry/configurable/compiler.rb
dry-configurable-0.11.4 lib/dry/configurable/compiler.rb
dry-configurable-0.11.3 lib/dry/configurable/compiler.rb
dry-configurable-0.11.2 lib/dry/configurable/compiler.rb
dry-configurable-0.11.1 lib/dry/configurable/compiler.rb
dry-configurable-0.11.0 lib/dry/configurable/compiler.rb