Exception: Kerbi::EntryValidationError

Inherits:
Error
  • Object
show all
Defined in:
lib/main/errors.rb

Constant Summary collapse

MSG =
"Cannot write state because of validation errors: "

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(errors) ⇒ EntryValidationError

Returns a new instance of EntryValidationError.

Parameters:

  • errors (Hash)


91
92
93
94
# File 'lib/main/errors.rb', line 91

def initialize(errors)
  message = self.class.build_message(errors)
  super(message)
end

Class Method Details

.build_message(errors) ⇒ Object

Parameters:

  • errors (Hash)


109
110
111
112
# File 'lib/main/errors.rb', line 109

def self.build_message(errors)
  parts = errors.map { |h| entry_line(h[0], h[1]) }
  "#{MSG} \n#{parts.join("\n")}"
end

.entry_line(tag, error_dicts) ⇒ Object

Parameters:

  • tag (String)
  • errors (Array<Hash>)


103
104
105
106
# File 'lib/main/errors.rb', line 103

def self.entry_line(tag, error_dicts)
  per_tag_parts = error_dicts.map{ |d| error_line(d) }
  "Entry['#{tag}'] \n #{per_tag_parts.join("\n")}".indent(1)
end

.error_line(error) ⇒ Object

Parameters:

  • errors (Hash)


97
98
99
# File 'lib/main/errors.rb', line 97

def self.error_line(error)
  "#{error[:attr]}['#{error[:value]}']: #{error[:msg]}".indent(1)
end