Class: Mutations::ErrorHash

Inherits:
Hash
  • Object
show all
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

Instance Method Details

#messageObject

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"
}

}



133
134
135
136
137
138
139
# File 'lib/mutations/errors.rb', line 133

def message
  HashWithIndifferentAccess.new.tap do |hash|
    each do |k, v|
      hash[k] = v.message
    end
  end
end

#message_listObject

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."

]



148
149
150
151
152
153
154
# File 'lib/mutations/errors.rb', line 148

def message_list
  list = []
  each do |k, v|
    list.concat(v.message_list)
  end
  list
end

#symbolicObject

Returns a nested HashWithIndifferentAccess where the values are symbols. Eg: {

email: :matches,
name: :too_weird,
adddress: {
  city: :not_found,
  state: :in
}

}



116
117
118
119
120
121
122
# File 'lib/mutations/errors.rb', line 116

def symbolic
  HashWithIndifferentAccess.new.tap do |hash|
    each do |k, v|
      hash[k] = v.symbolic
    end
  end
end