Class: Dry::Validation::ErrorCompiler
- Inherits:
-
Object
- Object
- Dry::Validation::ErrorCompiler
- Defined in:
- lib/dry/validation/error_compiler.rb
Instance Attribute Summary collapse
-
#messages ⇒ Object
readonly
Returns the value of attribute messages.
Instance Method Summary collapse
- #call(ast) ⇒ Object
-
#initialize(messages) ⇒ ErrorCompiler
constructor
A new instance of ErrorCompiler.
- #visit(node, *args) ⇒ Object
- #visit_empty?(*args, value) ⇒ Boolean
- #visit_eql?(*args, value) ⇒ Boolean
- #visit_error(error) ⇒ Object
- #visit_exclusion?(*args, value) ⇒ Boolean
- #visit_filled?(*args) ⇒ Boolean
- #visit_format?(*args, value) ⇒ Boolean
- #visit_gt?(*args, value) ⇒ Boolean
- #visit_gteq?(*args, value) ⇒ Boolean
- #visit_inclusion?(*args, value) ⇒ Boolean
- #visit_input(input, *args) ⇒ Object
- #visit_int?(*args, value) ⇒ Boolean
- #visit_key(rule, name, value) ⇒ Object
- #visit_key?(*args, value) ⇒ Boolean
- #visit_lt?(*args, value) ⇒ Boolean
- #visit_lteq?(*args, value) ⇒ Boolean
- #visit_max_size?(*args, value) ⇒ Boolean
- #visit_min_size?(*args, value) ⇒ Boolean
- #visit_nil?(*args, value) ⇒ Boolean
- #visit_predicate(predicate, value, name) ⇒ Object
- #visit_size?(*args, value) ⇒ Boolean
- #visit_str?(*args, value) ⇒ Boolean
- #visit_val(rule, name, value) ⇒ Object
Constructor Details
#initialize(messages) ⇒ ErrorCompiler
Returns a new instance of ErrorCompiler.
6 7 8 |
# File 'lib/dry/validation/error_compiler.rb', line 6 def initialize() @messages = end |
Instance Attribute Details
#messages ⇒ Object (readonly)
Returns the value of attribute messages.
4 5 6 |
# File 'lib/dry/validation/error_compiler.rb', line 4 def @messages end |
Instance Method Details
#call(ast) ⇒ Object
10 11 12 |
# File 'lib/dry/validation/error_compiler.rb', line 10 def call(ast) ast.map { |node| visit(node) } end |
#visit(node, *args) ⇒ Object
14 15 16 |
# File 'lib/dry/validation/error_compiler.rb', line 14 def visit(node, *args) __send__(:"visit_#{node[0]}", node[1], *args) end |
#visit_empty?(*args, value) ⇒ Boolean
45 46 47 |
# File 'lib/dry/validation/error_compiler.rb', line 45 def visit_empty?(*args, value) { value: value } end |
#visit_eql?(*args, value) ⇒ Boolean
85 86 87 |
# File 'lib/dry/validation/error_compiler.rb', line 85 def visit_eql?(*args, value) { eql_value: args[0][0], value: value } end |
#visit_error(error) ⇒ Object
18 19 20 |
# File 'lib/dry/validation/error_compiler.rb', line 18 def visit_error(error) visit(error) end |
#visit_exclusion?(*args, value) ⇒ Boolean
49 50 51 |
# File 'lib/dry/validation/error_compiler.rb', line 49 def visit_exclusion?(*args, value) { list: args[0][0].join(', ') } end |
#visit_filled?(*args) ⇒ Boolean
111 112 113 |
# File 'lib/dry/validation/error_compiler.rb', line 111 def visit_filled?(*args) {} end |
#visit_format?(*args, value) ⇒ Boolean
103 104 105 |
# File 'lib/dry/validation/error_compiler.rb', line 103 def visit_format?(*args, value) {} end |
#visit_gt?(*args, value) ⇒ Boolean
57 58 59 |
# File 'lib/dry/validation/error_compiler.rb', line 57 def visit_gt?(*args, value) { num: args[0][0], value: value } end |
#visit_gteq?(*args, value) ⇒ Boolean
61 62 63 |
# File 'lib/dry/validation/error_compiler.rb', line 61 def visit_gteq?(*args, value) { num: args[0][0], value: value } end |
#visit_inclusion?(*args, value) ⇒ Boolean
53 54 55 |
# File 'lib/dry/validation/error_compiler.rb', line 53 def visit_inclusion?(*args, value) { list: args[0][0].join(', ') } end |
#visit_input(input, *args) ⇒ Object
22 23 24 25 |
# File 'lib/dry/validation/error_compiler.rb', line 22 def visit_input(input, *args) name, value, rules = input [name, rules.map { |rule| visit(rule, name, value) }] end |
#visit_int?(*args, value) ⇒ Boolean
73 74 75 |
# File 'lib/dry/validation/error_compiler.rb', line 73 def visit_int?(*args, value) { num: args[0][0], value: value } end |
#visit_key(rule, name, value) ⇒ Object
27 28 29 30 |
# File 'lib/dry/validation/error_compiler.rb', line 27 def visit_key(rule, name, value) _, predicate = rule visit(predicate, value, name) end |
#visit_key?(*args, value) ⇒ Boolean
41 42 43 |
# File 'lib/dry/validation/error_compiler.rb', line 41 def visit_key?(*args, value) { name: args[0][0] } end |
#visit_lt?(*args, value) ⇒ Boolean
65 66 67 |
# File 'lib/dry/validation/error_compiler.rb', line 65 def visit_lt?(*args, value) { num: args[0][0], value: value } end |
#visit_lteq?(*args, value) ⇒ Boolean
69 70 71 |
# File 'lib/dry/validation/error_compiler.rb', line 69 def visit_lteq?(*args, value) { num: args[0][0], value: value } end |
#visit_max_size?(*args, value) ⇒ Boolean
77 78 79 |
# File 'lib/dry/validation/error_compiler.rb', line 77 def visit_max_size?(*args, value) { num: args[0][0], value: value } end |
#visit_min_size?(*args, value) ⇒ Boolean
81 82 83 |
# File 'lib/dry/validation/error_compiler.rb', line 81 def visit_min_size?(*args, value) { num: args[0][0], value: value } end |
#visit_nil?(*args, value) ⇒ Boolean
107 108 109 |
# File 'lib/dry/validation/error_compiler.rb', line 107 def visit_nil?(*args, value) {} end |
#visit_predicate(predicate, value, name) ⇒ Object
37 38 39 |
# File 'lib/dry/validation/error_compiler.rb', line 37 def visit_predicate(predicate, value, name) .lookup(predicate[0], name, predicate[1][0]) % visit(predicate, value).merge(name: name) end |
#visit_size?(*args, value) ⇒ Boolean
89 90 91 92 93 94 95 96 97 |
# File 'lib/dry/validation/error_compiler.rb', line 89 def visit_size?(*args, value) num = args[0][0] if num.is_a?(Range) { left: num.first, right: num.last, value: value } else { num: args[0][0], value: value } end end |
#visit_str?(*args, value) ⇒ Boolean
99 100 101 |
# File 'lib/dry/validation/error_compiler.rb', line 99 def visit_str?(*args, value) { value: value } end |
#visit_val(rule, name, value) ⇒ Object
32 33 34 35 |
# File 'lib/dry/validation/error_compiler.rb', line 32 def visit_val(rule, name, value) name, predicate = rule visit(predicate, value, name) end |