Class: VanillaValidator::Result

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

Overview

Result represents the outcome of a validation operation, including validated data and errors.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(validated, errors = {}) ⇒ Result

Returns a new instance of Result.



6
7
8
9
# File 'lib/vanilla_validator/result.rb', line 6

def initialize(validated, errors = {})
  @validated = validated.with_indifferent_access
  @errors = errors.with_indifferent_access
end

Instance Attribute Details

#errorsObject

Returns the value of attribute errors.



4
5
6
# File 'lib/vanilla_validator/result.rb', line 4

def errors
  @errors
end

#validatedObject

Returns the value of attribute validated.



4
5
6
# File 'lib/vanilla_validator/result.rb', line 4

def validated
  @validated
end

Instance Method Details

#failed?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/vanilla_validator/result.rb', line 15

def failed?
  errors.any?
end

#success?Boolean Also known as: valid?

Returns:

  • (Boolean)


11
12
13
# File 'lib/vanilla_validator/result.rb', line 11

def success?
  errors.empty?
end