Class: LHS::Errors
Overview
Like ActiveModel::Errors
Instance Attribute Summary collapse
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#messages ⇒ Object
readonly
Returns the value of attribute messages.
Instance Method Summary collapse
- #[](attribute) ⇒ Object
- #[]=(attribute, error) ⇒ Object
- #count ⇒ Object
- #delete(key) ⇒ Object
- #each ⇒ Object
- #empty? ⇒ Boolean
- #get(key) ⇒ Object
- #include?(attribute) ⇒ Boolean (also: #has_key?, #key?)
-
#initialize(response) ⇒ Errors
constructor
A new instance of Errors.
- #keys ⇒ Object
- #set(key, value) ⇒ Object
- #size ⇒ Object
- #values ⇒ Object
Constructor Details
#initialize(response) ⇒ Errors
Returns a new instance of Errors.
7 8 9 10 11 |
# File 'lib/lhs/errors.rb', line 7 def initialize(response) @messages = (response) @message = (response) rescue JSON::ParserError end |
Instance Attribute Details
#message ⇒ Object (readonly)
Returns the value of attribute message.
5 6 7 |
# File 'lib/lhs/errors.rb', line 5 def @message end |
#messages ⇒ Object (readonly)
Returns the value of attribute messages.
5 6 7 |
# File 'lib/lhs/errors.rb', line 5 def @messages end |
Instance Method Details
#[](attribute) ⇒ Object
31 32 33 |
# File 'lib/lhs/errors.rb', line 31 def [](attribute) get(attribute.to_sym) || set(attribute.to_sym, []) end |
#[]=(attribute, error) ⇒ Object
35 36 37 |
# File 'lib/lhs/errors.rb', line 35 def []=(attribute, error) self[attribute] << error end |
#count ⇒ Object
57 58 59 |
# File 'lib/lhs/errors.rb', line 57 def count to_a.size end |
#delete(key) ⇒ Object
27 28 29 |
# File 'lib/lhs/errors.rb', line 27 def delete(key) .delete(key) end |
#each ⇒ Object
39 40 41 42 43 |
# File 'lib/lhs/errors.rb', line 39 def each .each_key do |attribute| self[attribute].each { |error| yield attribute, error } end end |
#empty? ⇒ Boolean
61 62 63 |
# File 'lib/lhs/errors.rb', line 61 def empty? all? { |k, v| v && v.empty? && !v.is_a?(String) } end |
#get(key) ⇒ Object
19 20 21 |
# File 'lib/lhs/errors.rb', line 19 def get(key) [key] end |
#include?(attribute) ⇒ Boolean Also known as: has_key?, key?
13 14 15 |
# File 'lib/lhs/errors.rb', line 13 def include?(attribute) [attribute].present? end |
#keys ⇒ Object
53 54 55 |
# File 'lib/lhs/errors.rb', line 53 def keys .keys end |
#set(key, value) ⇒ Object
23 24 25 |
# File 'lib/lhs/errors.rb', line 23 def set(key, value) [key] = value end |
#size ⇒ Object
45 46 47 |
# File 'lib/lhs/errors.rb', line 45 def size values.flatten.size end |
#values ⇒ Object
49 50 51 |
# File 'lib/lhs/errors.rb', line 49 def values .values end |