Class: Objective::Errors::ErrorHash
- Inherits:
-
Hash
- Object
- Hash
- Objective::Errors::ErrorHash
- Defined in:
- lib/objective/errors/error_hash.rb
Instance Method Summary collapse
-
#codes ⇒ Object
Returns a nested Hash where the values are symbols.
-
#message(_parent_key = nil, _index = nil) ⇒ Object
Returns a nested Hash where the values are messages.
-
#message_list(_parent_key = nil, _index = nil) ⇒ Object
Returns a flat array where each element is a full sentence.
Instance Method Details
#codes ⇒ Object
Returns a nested Hash where the values are symbols. Eg: { email: :matches, name: :too_weird, adddress: { city: :not_found, state: :in } }
25 26 27 28 29 30 31 |
# File 'lib/objective/errors/error_hash.rb', line 25 def codes {}.tap do |hash| each do |k, v| hash[k] = v.codes end end end |
#message(_parent_key = nil, _index = nil) ⇒ Object
Returns a nested Hash where the values are messages. Eg: { email: "isn't in the right format", name: "is too weird", adddress: { city: "is not a city", state: "isn't a valid option" } }
42 43 44 45 46 47 48 |
# File 'lib/objective/errors/error_hash.rb', line 42 def (_parent_key = nil, _index = nil) {}.tap do |hash| each do |k, v| hash[k] = v.(k) end end end |
#message_list(_parent_key = nil, _index = nil) ⇒ Object
Returns a flat array where each element is a full sentence. Eg: [ "Email isn't in the right format.", "Name is too weird", "That's not a city, silly!", "State isn't a valid option." ]
57 58 59 60 61 62 63 |
# File 'lib/objective/errors/error_hash.rb', line 57 def (_parent_key = nil, _index = nil) list = [] each do |k, v| list.concat(v.(k)) end list end |