Class: Mutations::ErrorHash
- Inherits:
-
Hash
- Object
- Hash
- Mutations::ErrorHash
- Defined in:
- lib/mutations/errors.rb
Overview
mutation.errors is an ErrorHash instance like this: {
email: ErrorAtom(:matches),
name: ErrorAtom(:too_weird, message: "is too weird"),
adddress: { # Nested ErrorHash object
city: ErrorAtom(:not_found, message: "That's not a city, silly!"),
state: ErrorAtom(:in)
}
}
Instance Method Summary collapse
-
#message ⇒ Object
Returns a nested HashWithIndifferentAccess where the values are messages.
-
#message_list ⇒ Object
Returns a flat array where each element is a full sentence.
-
#symbolic ⇒ Object
Returns a nested HashWithIndifferentAccess where the values are symbols.
Instance Method Details
#message ⇒ Object
Returns a nested HashWithIndifferentAccess 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"
}
}
122 123 124 125 126 127 128 |
# File 'lib/mutations/errors.rb', line 122 def HashWithIndifferentAccess.new.tap do |hash| each do |k, v| hash[k] = v. end end end |
#message_list ⇒ 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."
]
137 138 139 140 141 142 143 |
# File 'lib/mutations/errors.rb', line 137 def list = [] each do |k, v| list.concat(v.) end list end |
#symbolic ⇒ Object
Returns a nested HashWithIndifferentAccess where the values are symbols. Eg: {
email: :matches,
name: :too_weird,
adddress: {
city: :not_found,
state: :in
}
}
105 106 107 108 109 110 111 |
# File 'lib/mutations/errors.rb', line 105 def symbolic HashWithIndifferentAccess.new.tap do |hash| each do |k, v| hash[k] = v.symbolic end end end |