Sha256: 35010e0bbd1078133f02be6ce96bcff900318cc94bc300f951cc77c30178887f

Contents?: true

Size: 958 Bytes

Versions: 38

Compression:

Stored size: 958 Bytes

Contents

# frozen_string_literal: true

module Dry
  module Schema
    # A special rule type that is configured under a specified namespace
    #
    # This is used internally to create rules that can be properly handled
    # by the message compiler in situations where a schema reuses another schema
    # but it is configured to use a message namespace
    #
    # @api private
    class NamespacedRule
      # @api private
      attr_reader :rule

      # @api private
      attr_reader :namespace

      # @api private
      def initialize(namespace, rule)
        @namespace = namespace
        @rule = rule
      end

      # @api private
      def call(input)
        result = rule.call(input)
        Logic::Result.new(result.success?) { [:namespace, [namespace, result.to_ast]] }
      end

      # @api private
      def ast(input = Undefined)
        [:namespace, [namespace, rule.ast(input)]]
      end
      alias_method :to_ast, :ast
    end
  end
end

Version data entries

38 entries across 38 versions & 1 rubygems

Version Path
dry-schema-1.13.3 lib/dry/schema/namespaced_rule.rb
dry-schema-1.13.2 lib/dry/schema/namespaced_rule.rb
dry-schema-1.13.1 lib/dry/schema/namespaced_rule.rb
dry-schema-1.13.0 lib/dry/schema/namespaced_rule.rb
dry-schema-1.12.0 lib/dry/schema/namespaced_rule.rb
dry-schema-1.11.3 lib/dry/schema/namespaced_rule.rb
dry-schema-1.11.2 lib/dry/schema/namespaced_rule.rb
dry-schema-1.11.1 lib/dry/schema/namespaced_rule.rb
dry-schema-1.11.0 lib/dry/schema/namespaced_rule.rb
dry-schema-1.10.6 lib/dry/schema/namespaced_rule.rb
dry-schema-1.10.5 lib/dry/schema/namespaced_rule.rb
dry-schema-1.10.4 lib/dry/schema/namespaced_rule.rb
dry-schema-1.10.3 lib/dry/schema/namespaced_rule.rb
dry-schema-1.10.2 lib/dry/schema/namespaced_rule.rb
dry-schema-1.10.1 lib/dry/schema/namespaced_rule.rb
dry-schema-1.9.3 lib/dry/schema/namespaced_rule.rb
dry-schema-1.9.2 lib/dry/schema/namespaced_rule.rb
dry-schema-1.9.1 lib/dry/schema/namespaced_rule.rb
dry-schema-1.9.0 lib/dry/schema/namespaced_rule.rb
dry-schema-1.8.0 lib/dry/schema/namespaced_rule.rb