Class: Dry::Validation::Rust::Rule
- Inherits:
-
Object
- Object
- Dry::Validation::Rust::Rule
- Defined in:
- lib/dry/validation/rust/rule.rb
Instance Attribute Summary collapse
-
#block ⇒ Object
readonly
Returns the value of attribute block.
-
#default_path ⇒ Object
readonly
Returns the value of attribute default_path.
-
#keyword_params ⇒ Object
readonly
Returns the value of attribute keyword_params.
-
#macro_calls ⇒ Object
readonly
Returns the value of attribute macro_calls.
-
#paths ⇒ Object
readonly
Returns the value of attribute paths.
Instance Method Summary collapse
- #each(*macros, &new_block) ⇒ Object
- #each? ⇒ Boolean
-
#initialize(paths:, default_path: paths.first || [], block: nil) ⇒ Rule
constructor
A new instance of Rule.
- #inspect ⇒ Object
- #validate(*macros, &new_block) ⇒ Object
Constructor Details
#initialize(paths:, default_path: paths.first || [], block: nil) ⇒ Rule
Returns a new instance of Rule.
11 12 13 14 15 16 17 |
# File 'lib/dry/validation/rust/rule.rb', line 11 def initialize(paths:, default_path: paths.first || [], block: nil) @paths = paths @default_path = default_path assign_block(block) @macro_calls = [] @each = false end |
Instance Attribute Details
#block ⇒ Object (readonly)
Returns the value of attribute block.
9 10 11 |
# File 'lib/dry/validation/rust/rule.rb', line 9 def block @block end |
#default_path ⇒ Object (readonly)
Returns the value of attribute default_path.
9 10 11 |
# File 'lib/dry/validation/rust/rule.rb', line 9 def default_path @default_path end |
#keyword_params ⇒ Object (readonly)
Returns the value of attribute keyword_params.
9 10 11 |
# File 'lib/dry/validation/rust/rule.rb', line 9 def keyword_params @keyword_params end |
#macro_calls ⇒ Object (readonly)
Returns the value of attribute macro_calls.
9 10 11 |
# File 'lib/dry/validation/rust/rule.rb', line 9 def macro_calls @macro_calls end |
#paths ⇒ Object (readonly)
Returns the value of attribute paths.
9 10 11 |
# File 'lib/dry/validation/rust/rule.rb', line 9 def paths @paths end |
Instance Method Details
#each(*macros, &new_block) ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/dry/validation/rust/rule.rb', line 25 def each(*macros, &new_block) raise ArgumentError, 'rule.each requires exactly one root key' unless paths.length == 1 @each = true assign_block(new_block) if new_block @macro_calls = parse_macros(macros) self end |
#each? ⇒ Boolean
34 35 36 |
# File 'lib/dry/validation/rust/rule.rb', line 34 def each? @each end |
#inspect ⇒ Object
38 39 40 |
# File 'lib/dry/validation/rust/rule.rb', line 38 def inspect "#<#{self.class} paths=#{paths.inspect} each=#{each?}>" end |
#validate(*macros, &new_block) ⇒ Object
19 20 21 22 23 |
# File 'lib/dry/validation/rust/rule.rb', line 19 def validate(*macros, &new_block) assign_block(new_block) if new_block @macro_calls = parse_macros(macros) self end |