Exception: Gourami::ValidationError

Inherits:
Error
  • Object
show all
Defined in:
lib/gourami/validation_error.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(errors, resource_errors = {}) ⇒ ValidationError

Initialize the Gourami::ValidationError.

Parameters:

  • errors (Hash<Symbol, Array>)
  • resource_errors (Hash<Symbol, Hash<Symbol, Hash<Symbol, Array>>>) (defaults to: {})


36
37
38
39
40
41
# File 'lib/gourami/validation_error.rb', line 36

def initialize(errors, resource_errors = {})
  @resource_errors = resource_errors
  @errors = errors

  super(message)
end

Instance Attribute Details

#errorsObject (readonly)

!@attribute [r] errors

@return [Hash<Symbol, Array>]


26
27
28
# File 'lib/gourami/validation_error.rb', line 26

def errors
  @errors
end

#resource_errorsObject (readonly)

!@attribute [r] resource_errors

@return [Hash<Symbol, Hash<Symbol, Hash<Symbol, Array>>>]


30
31
32
# File 'lib/gourami/validation_error.rb', line 30

def resource_errors
  @resource_errors
end

Class Method Details

.stringify_errors(errors) ⇒ Object



4
5
6
7
8
9
10
# File 'lib/gourami/validation_error.rb', line 4

def self.stringify_errors(errors)
  [].tap do |array|
    errors.each do |field, error|
      array.push("#{field}: #{error}")
    end
  end
end

.stringify_resource_errors(resource_errors) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/gourami/validation_error.rb', line 12

def self.stringify_resource_errors(resource_errors)
  [].tap do |array|
    resource_errors.each do |resource_namespace, resource_namespace_errors|
      resource_namespace_errors.each do |resource_uid, resource_uid_errors|
        resource_uid_errors.each do |attribute_name, error|
           array.push("#{resource_namespace}:#{resource_uid}:#{attribute_name}: #{error}")
        end
      end
    end
  end
end

Instance Method Details

#messageObject



43
44
45
# File 'lib/gourami/validation_error.rb', line 43

def message
  @message ||= stringify_all_errors
end