Class: Objective::Errors::ErrorHash

Inherits:
Hash
  • Object
show all
Defined in:
lib/objective/errors/error_hash.rb

Instance Method Summary collapse

Instance Method Details

#codesObject

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 message(_parent_key = nil, _index = nil)
  {}.tap do |hash|
    each do |k, v|
      hash[k] = v.message(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 message_list(_parent_key = nil, _index = nil)
  list = []
  each do |k, v|
    list.concat(v.message_list(k))
  end
  list
end