Class: SmartCore::Validator::Result

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(errors:, data:, failed:) ⇒ Result

Returns a new instance of Result.



17
18
19
20
21
# File 'lib/smart_core/validator/result.rb', line 17

def initialize(errors:, data:, failed:)
  self.errors = errors
  self.data = data
  self.failed = failed
end

Instance Attribute Details

#dataObject Also known as: to_h

Returns the value of attribute data.



5
6
7
# File 'lib/smart_core/validator/result.rb', line 5

def data
  @data
end

#errorsObject

Returns the value of attribute errors.



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

def errors
  @errors
end

#failedObject Also known as: failed?

Returns the value of attribute failed.



6
7
8
# File 'lib/smart_core/validator/result.rb', line 6

def failed
  @failed
end

Class Method Details

.build_from_state(input_data, errors_controller) ⇒ Object



8
9
10
11
12
13
14
15
# File 'lib/smart_core/validator/result.rb', line 8

def self.build_from_state(input_data, errors_controller)
  res = new(
    data: input_data,
    errors: errors_controller.errors,
    failed: errors_controller.validation_fails?
  )
  res.freeze
end

Instance Method Details

#freezeObject



27
28
29
30
31
32
# File 'lib/smart_core/validator/result.rb', line 27

def freeze
  super.tap do
    errors.freeze
    data.freeze
  end
end

#success?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/smart_core/validator/result.rb', line 23

def success?
  !failed
end