Class: SimplerCommand::Errors
- Inherits:
-
Hash
- Object
- Hash
- SimplerCommand::Errors
- Defined in:
- lib/simpler_command/errors.rb
Overview
Provides an Errors implementation similar to ActiveModel::Errors
Instance Method Summary collapse
- #add(key, value, _opts = {}) ⇒ Object
- #add_all(errors_hash) ⇒ Object
-
#as_json(options = nil) ⇒ Object
Allow ActiveSupport to render errors similar to ActiveModel::Errors.
- #each ⇒ Object
- #full_messages ⇒ Object
Instance Method Details
#add(key, value, _opts = {}) ⇒ Object
6 7 8 9 10 |
# File 'lib/simpler_command/errors.rb', line 6 def add(key, value, _opts = {}) self[key] ||= [] self[key] << value self[key].uniq! end |
#add_all(errors_hash) ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/simpler_command/errors.rb', line 12 def add_all(errors_hash) errors_hash.each do |key, values| Array(values).each do |value| add key, value end end end |
#as_json(options = nil) ⇒ Object
Allow ActiveSupport to render errors similar to ActiveModel::Errors
31 32 33 34 35 36 37 38 |
# File 'lib/simpler_command/errors.rb', line 31 def as_json( = nil) {}.tap do |output| each do |field, value| output[field] ||= [] output[field] << value end end.as_json() end |
#each ⇒ Object
20 21 22 23 24 |
# File 'lib/simpler_command/errors.rb', line 20 def each each_key do |field| self[field].each { || yield field, } end end |
#full_messages ⇒ Object
26 27 28 |
# File 'lib/simpler_command/errors.rb', line 26 def map { |attribute, | (attribute, ) } end |