Class: RDStation::Error::Formatter
- Inherits:
-
Object
- Object
- RDStation::Error::Formatter
- Defined in:
- lib/rdstation/error/formatter.rb
Instance Method Summary collapse
- #error_format ⇒ Object
- #from_flat_hash ⇒ Object
- #from_hash_of_arrays ⇒ Object
-
#initialize(errors) ⇒ Formatter
constructor
A new instance of Formatter.
- #to_array ⇒ Object
Constructor Details
#initialize(errors) ⇒ Formatter
Returns a new instance of Formatter.
6 7 8 |
# File 'lib/rdstation/error/formatter.rb', line 6 def initialize(errors) @errors = errors end |
Instance Method Details
#error_format ⇒ Object
35 36 37 |
# File 'lib/rdstation/error/formatter.rb', line 35 def error_format @error_format ||= RDStation::Error::Format.new(@errors) end |
#from_flat_hash ⇒ Object
21 22 23 |
# File 'lib/rdstation/error/formatter.rb', line 21 def from_flat_hash [@errors] end |
#from_hash_of_arrays ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'lib/rdstation/error/formatter.rb', line 25 def from_hash_of_arrays @errors.each_with_object([]) do |errors, array_of_errors| attribute_name = errors.first attribute_errors = errors.last path = { 'path' => "body.#{attribute_name}" } errors = attribute_errors.map { |error| error.merge(path) } array_of_errors.push(*errors) end end |