Sha256: c5c88088b9b6deae2c15b2f00468b1f30ff1807ed5f86de1e6c5267e3550eb9d

Contents?: true

Size: 781 Bytes

Versions: 7

Compression:

Stored size: 781 Bytes

Contents

# frozen_string_literal: true

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_setting(node)
        name, opts = node
        Setting.new(name, **opts)
      end

      # @api private
      def visit_nested(node)
        parent, children = node
        name, opts = parent[1]

        Setting.new(name, **opts, children: Settings.new(call(children)))
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
dry-configurable-1.3.0 lib/dry/configurable/compiler.rb
dry-configurable-1.2.0 lib/dry/configurable/compiler.rb
dry-configurable-1.1.0 lib/dry/configurable/compiler.rb
dry-configurable-1.0.1 lib/dry/configurable/compiler.rb
dry-configurable-1.0.0 lib/dry/configurable/compiler.rb
dry-configurable-0.16.1 lib/dry/configurable/compiler.rb
dry-configurable-0.16.0 lib/dry/configurable/compiler.rb