Class: Dry::Validation::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/dry/validation/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
# File 'lib/dry/validation/result.rb', line 33

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

Instance Attribute Details

#inputObject (readonly)

Returns the value of attribute input.



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

def input
  @input
end

#ruleObject (readonly)

Returns the value of attribute rule.



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

def rule
  @rule
end

#valueObject (readonly)

Returns the value of attribute value.



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

def value
  @value
end

Instance Method Details

#and(other) ⇒ Object



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

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

#failure?Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/dry/validation/result.rb', line 59

def failure?
  ! success?
end

#or(other) ⇒ Object



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

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

#success?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/dry/validation/result.rb', line 55

def success?
  @value
end