Class: Dry::Validation::Rule::Result

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

Direct Known Subclasses

Set, Value

Defined Under Namespace

Classes: Set, Value

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input, value, rule) ⇒ Result

Returns a new instance of Result.



33
34
35
36
37
38
# File 'lib/dry/validation/rule/result.rb', line 33

def initialize(input, value, rule)
  @input = input
  @value = value
  @rule = rule
  @name = rule.name
end

Instance Attribute Details

#inputObject (readonly)

Returns the value of attribute input.



13
14
15
# File 'lib/dry/validation/rule/result.rb', line 13

def input
  @input
end

#nameObject (readonly)

Returns the value of attribute name.



13
14
15
# File 'lib/dry/validation/rule/result.rb', line 13

def name
  @name
end

#ruleObject (readonly)

Returns the value of attribute rule.



13
14
15
# File 'lib/dry/validation/rule/result.rb', line 13

def rule
  @rule
end

#valueObject (readonly)

Returns the value of attribute value.



13
14
15
# File 'lib/dry/validation/rule/result.rb', line 13

def value
  @value
end

Instance Method Details

#>(other) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/dry/validation/rule/result.rb', line 40

def >(other)
  if success?
    other.(input)
  else
    Validation.Result(input, true, rule)
  end
end

#and(other) ⇒ Object



48
49
50
51
52
53
54
# File 'lib/dry/validation/rule/result.rb', line 48

def and(other)
  if success?
    other.(input)
  else
    self
  end
end

#failure?Boolean

Returns:

  • (Boolean)


68
69
70
# File 'lib/dry/validation/rule/result.rb', line 68

def failure?
  ! success?
end

#or(other) ⇒ Object



56
57
58
59
60
61
62
# File 'lib/dry/validation/rule/result.rb', line 56

def or(other)
  if success?
    self
  else
    other.(input)
  end
end

#success?Boolean

Returns:

  • (Boolean)


64
65
66
# File 'lib/dry/validation/rule/result.rb', line 64

def success?
  @value
end