class Gourami::ValidationError

Attributes

errors[R]

!@attribute [r] errors

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

!@attribute [r] resource_errors

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

Public Class Methods

new(errors, resource_errors = {}) click to toggle source

Initialize the Gourami::ValidationError.

@param errors [Hash<Symbol, Array>] @param resource_errors [Hash<Symbol, Hash<Symbol, Hash<Symbol, Array>>>]

Calls superclass method
# File lib/gourami/validation_error.rb, line 36
def initialize(errors, resource_errors = {})
  @resource_errors = resource_errors
  @errors = errors

  super(message)
end
stringify_errors(errors) click to toggle source
# 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) click to toggle source
# 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

Public Instance Methods

message() click to toggle source
# File lib/gourami/validation_error.rb, line 43
def message
  @message ||= stringify_all_errors
end

Private Instance Methods

stringify_all_errors() click to toggle source
# File lib/gourami/validation_error.rb, line 57
def stringify_all_errors
  messages = []
  messages << "Validation failed with errors: #{stringify_errors.join("\n")}" unless errors.nil? || errors.empty?
  messages << "Validation failed with resource errors: #{stringify_resource_errors.join("\n")}" unless resource_errors.nil? || resource_errors.empty?
  messages.join("\n")
end
stringify_errors() click to toggle source
# File lib/gourami/validation_error.rb, line 49
def stringify_errors
  ValidationError.stringify_errors(errors)
end
stringify_resource_errors() click to toggle source
# File lib/gourami/validation_error.rb, line 53
def stringify_resource_errors
  ValidationError.stringify_resource_errors(resource_errors)
end