Sha256: 77dac7efc1eaaf1673cc84e1b3d9b2517c35038c94ce150b86a99c62f7d86349

Contents?: true

Size: 1.13 KB

Versions: 10

Compression:

Stored size: 1.13 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 {}, 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)
          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

10 entries across 10 versions & 1 rubygems

Version Path
dry-schema-1.10.6 lib/dry/schema/macros/core.rb
dry-schema-1.10.5 lib/dry/schema/macros/core.rb
dry-schema-1.10.4 lib/dry/schema/macros/core.rb
dry-schema-1.10.3 lib/dry/schema/macros/core.rb
dry-schema-1.10.2 lib/dry/schema/macros/core.rb
dry-schema-1.10.1 lib/dry/schema/macros/core.rb
dry-schema-1.9.3 lib/dry/schema/macros/core.rb
dry-schema-1.9.2 lib/dry/schema/macros/core.rb
dry-schema-1.9.1 lib/dry/schema/macros/core.rb
dry-schema-1.9.0 lib/dry/schema/macros/core.rb