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



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

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

Instance Method Details

#call(other) ⇒ Object



31
32
33
# File 'lib/dry/validation/message_compiler/visitor_opts.rb', line 31

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

#pathObject



17
18
19
# File 'lib/dry/validation/message_compiler/visitor_opts.rb', line 17

def path
  self[:path]
end

#path?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/dry/validation/message_compiler/visitor_opts.rb', line 13

def path?
  ! path.empty?
end

#ruleObject



21
22
23
# File 'lib/dry/validation/message_compiler/visitor_opts.rb', line 21

def rule
  self[:rule]
end

#with_rule(new_rule, **other) ⇒ Object



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

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