Sha256: 24514b0595de628260a707fec72dd5eb778814f8d9a0f8d16efad286ab520c9c

Contents?: true

Size: 1.12 KB

Versions: 2

Compression:

Stored size: 1.12 KB

Contents

# frozen_string_literal: true

require "dry/initializer"
require "dry/schema/constants"

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

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

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

        # @api private
        option :schema_dsl, optional: true

        # @api private
        option :trace, default: proc { Trace.new(schema_dsl&.compiler || Compiler.new) }

        # @api private
        def new(**options)
          self.class.new(name: name, compiler: compiler, schema_dsl: schema_dsl, **options)
        end

        # @api private
        def path
          schema_dsl.path
        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

2 entries across 2 versions & 1 rubygems

Version Path
dry-schema-1.13.3 lib/dry/schema/macros/core.rb
dry-schema-1.13.2 lib/dry/schema/macros/core.rb