Exception: Rbdantic::ValidationError

Inherits:
StandardError
  • Object
show all
Defined in:
lib/rbdantic/error_detail.rb

Overview

Raised when model validation fails

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(errors) ⇒ ValidationError

Returns a new instance of ValidationError.



32
33
34
35
# File 'lib/rbdantic/error_detail.rb', line 32

def initialize(errors)
  @errors = errors
  super(build_message)
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



30
31
32
# File 'lib/rbdantic/error_detail.rb', line 30

def errors
  @errors
end

Instance Method Details

#as_jsonObject Also known as: to_h



41
42
43
# File 'lib/rbdantic/error_detail.rb', line 41

def as_json(*)
  { errors: @errors.map(&:as_json), error_count: error_count }
end

#error_countObject



37
38
39
# File 'lib/rbdantic/error_detail.rb', line 37

def error_count
  @errors.length
end