Class: Dry::Validation::Rust::Rule

Inherits:
Object
  • Object
show all
Defined in:
lib/dry/validation/rust/rule.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#blockObject (readonly)

Returns the value of attribute block.



9
10
11
# File 'lib/dry/validation/rust/rule.rb', line 9

def block
  @block
end

#default_pathObject (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_paramsObject (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_callsObject (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

#pathsObject (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

Raises:

  • (ArgumentError)


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

Returns:

  • (Boolean)


34
35
36
# File 'lib/dry/validation/rust/rule.rb', line 34

def each?
  @each
end

#inspectObject



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