Class: Ward::Support::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/ward/support/result.rb

Overview

Used when validating objects which don’t include the Validation module. Contains the results of running a ValidatorSet against a record, and any errors which occurred.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(errors) ⇒ Result

Creates a new Result instance.

Parameters:

  • errors (Ward::Errors)

    The errors which were found by the validations.



24
25
26
27
# File 'lib/ward/support/result.rb', line 24

def initialize(errors)
  @errors = errors
  @result = errors.empty?
end

Instance Attribute Details

#errorsWard:Errors (readonly)

Returns the errors which were found when validating.

An Errors instance will always be returned, even if there were no errors with the record.

Returns:

  • (Ward:Errors)


17
18
19
# File 'lib/ward/support/result.rb', line 17

def errors
  @errors
end

Instance Method Details

#fail?Boolean

Returns true if the validations failed.

Returns:

  • (Boolean)


43
44
45
# File 'lib/ward/support/result.rb', line 43

def fail?
  not pass?
end

#pass?Boolean Also known as: valid?

Returns true if the validations passed.

Returns:

  • (Boolean)


33
34
35
# File 'lib/ward/support/result.rb', line 33

def pass?
  @result
end