Sha256: c8bf3e51bad187c1a257636e4cd71419166ebb7be3c7918b637c4486970b320b

Contents?: true

Size: 743 Bytes

Versions: 4

Compression:

Stored size: 743 Bytes

Contents

require 'dry/core/constants'

module Dry
  module Validation
    class MessageCompiler
      class VisitorOpts < Hash
        def self.new
          opts = super
          opts[:path] = Core::Constants::EMPTY_ARRAY
          opts[:rule] = nil
          opts[:message_type] = :failure
          opts
        end

        def path?
          ! path.empty?
        end

        def path
          self[:path]
        end

        def rule
          self[:rule]
        end

        def with_rule(new_rule, **other)
          opts = dup
          opts[:rule] = new_rule unless opts.rule
          opts.(other)
        end

        def call(other)
          merge(other.update(path: [*path, *other[:path]]))
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
dry-validation-0.10.3 lib/dry/validation/message_compiler/visitor_opts.rb
dry-validation-0.10.2 lib/dry/validation/message_compiler/visitor_opts.rb
dry-validation-0.10.1 lib/dry/validation/message_compiler/visitor_opts.rb
dry-validation-0.10.0 lib/dry/validation/message_compiler/visitor_opts.rb