Class: Dry::Validation::MessageCompiler::VisitorOpts

Inherits:
Hash
  • Object
show all
Defined in:
lib/dry/validation/message_compiler/visitor_opts.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.newObject



7
8
9
10
11
12
13
# File 'lib/dry/validation/message_compiler/visitor_opts.rb', line 7

def self.new
  opts = super
  opts[:path] = Core::Constants::EMPTY_ARRAY
  opts[:rule] = nil
  opts[:message_type] = :failure
  opts
end

Instance Method Details

#call(other) ⇒ Object



33
34
35
# File 'lib/dry/validation/message_compiler/visitor_opts.rb', line 33

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

#pathObject



19
20
21
# File 'lib/dry/validation/message_compiler/visitor_opts.rb', line 19

def path
  self[:path]
end

#path?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/dry/validation/message_compiler/visitor_opts.rb', line 15

def path?
  ! path.empty?
end

#ruleObject



23
24
25
# File 'lib/dry/validation/message_compiler/visitor_opts.rb', line 23

def rule
  self[:rule]
end

#with_rule(new_rule, **other) ⇒ Object



27
28
29
30
31
# File 'lib/dry/validation/message_compiler/visitor_opts.rb', line 27

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