Sha256: 2b04f976587909fd43933f69ff715beefce76c5be4963397db288bcd29de498c

Contents?: true

Size: 1.08 KB

Versions: 18

Compression:

Stored size: 1.08 KB

Contents

# frozen_string_literal: true

require 'dry/initializer'

require 'dry/schema/constants'
require 'dry/schema/compiler'
require 'dry/schema/trace'

module Dry
  module Schema
    module Macros
      # Abstract macro class
      #
      # @api private
      class Core
        extend Dry::Initializer

        # @api private
        option :name, default: proc { nil }, optional: true

        # @api private
        option :compiler, default: proc { Compiler.new }

        # @api private
        option :trace, default: proc { Trace.new }

        # @api private
        option :schema_dsl, optional: true

        # @api private
        def new(options = EMPTY_HASH)
          self.class.new({ name: name, compiler: compiler, schema_dsl: schema_dsl }.merge(options))
        end

        # @api private
        def to_rule
          compiler.visit(to_ast)
        end

        # @api private
        def to_ast(*)
          trace.to_ast
        end
        alias_method :ast, :to_ast

        # @api private
        def operation
          raise NotImplementedError
        end
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
dry-schema-1.4.1 lib/dry/schema/macros/core.rb
dry-schema-1.4.0 lib/dry/schema/macros/core.rb
dry-schema-1.3.4 lib/dry/schema/macros/core.rb
dry-schema-1.3.3 lib/dry/schema/macros/core.rb
dry-schema-1.3.2 lib/dry/schema/macros/core.rb
dry-schema-1.3.1 lib/dry/schema/macros/core.rb
dry-schema-1.3.0 lib/dry/schema/macros/core.rb
dry-schema-1.2.0 lib/dry/schema/macros/core.rb
dry-schema-1.1.0 lib/dry/schema/macros/core.rb
dry-schema-1.0.3 lib/dry/schema/macros/core.rb
dry-schema-1.0.2 lib/dry/schema/macros/core.rb
dry-schema-1.0.1 lib/dry/schema/macros/core.rb
dry-schema-1.0.0 lib/dry/schema/macros/core.rb
dry-schema-0.6.0 lib/dry/schema/macros/core.rb
dry-schema-0.5.1 lib/dry/schema/macros/core.rb
dry-schema-0.5.0 lib/dry/schema/macros/core.rb
dry-schema-0.4.0 lib/dry/schema/macros/core.rb
dry-schema-0.3.0 lib/dry/schema/macros/core.rb