Class: Attestor::Report

Inherits:
Object
  • Object
show all
Defined in:
lib/attestor/report.rb

Overview

Describes the result, returned by safe validation

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object, error = nil) ⇒ Report

Returns a new instance of Report.



9
10
11
12
13
# File 'lib/attestor/report.rb', line 9

def initialize(object, error = nil)
  @object = object
  @error  = error
  freeze
end

Instance Attribute Details

#errorAttestor::InvalidError? (readonly)

The exception raised by validation

Returns:



26
27
28
# File 'lib/attestor/report.rb', line 26

def error
  @error
end

#objectObject (readonly)

The object being validated

Returns:

  • (Object)


19
20
21
# File 'lib/attestor/report.rb', line 19

def object
  @object
end

Instance Method Details

#invalid?Boolean

Checks whether validation fails

Returns:

  • (Boolean)


38
39
40
# File 'lib/attestor/report.rb', line 38

def invalid?
  !valid?
end

#messagesArray<String>

Returns the list of error messages

Returns:

  • (Array<String>)


45
46
47
# File 'lib/attestor/report.rb', line 45

def messages
  error ? error.messages : []
end

#valid?Boolean

Checks whether validation passes

Returns:

  • (Boolean)


31
32
33
# File 'lib/attestor/report.rb', line 31

def valid?
  error.blank?
end