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.
-
#raw ⇒ Object
readonly
Returns the value of attribute raw.
Instance Method Summary collapse
- #[](attribute) ⇒ Object
- #[]=(attribute, error) ⇒ Object
- #count ⇒ Object
- #each ⇒ Object
- #empty? ⇒ Boolean
- #get(key) ⇒ Object
- #include?(attribute) ⇒ Boolean (also: #has_key?, #key?)
-
#initialize(response) ⇒ Errors
constructor
A new instance of Errors.
- #set(key, value) ⇒ Object
- #size ⇒ Object
Constructor Details
#initialize(response) ⇒ Errors
Returns a new instance of Errors.
7 8 9 10 11 12 |
# File 'lib/lhs/errors.rb', line 7 def initialize(response) = (response) = (response) @raw = response.body rescue JSON::ParserError # rubocop:disable Lint/HandleExceptions end |
Instance Attribute Details
#message ⇒ Object (readonly)
Returns the value of attribute message.
5 6 7 |
# File 'lib/lhs/errors.rb', line 5 def end |
#messages ⇒ Object (readonly)
Returns the value of attribute messages.
5 6 7 |
# File 'lib/lhs/errors.rb', line 5 def end |
#raw ⇒ Object (readonly)
Returns the value of attribute raw.
5 6 7 |
# File 'lib/lhs/errors.rb', line 5 def raw @raw end |
Instance Method Details
#[](attribute) ⇒ Object
30 31 32 |
# File 'lib/lhs/errors.rb', line 30 def [](attribute) get(attribute.to_sym) || set(attribute.to_sym, []) end |
#[]=(attribute, error) ⇒ Object
34 35 36 |
# File 'lib/lhs/errors.rb', line 34 def []=(attribute, error) self[attribute] << error end |
#count ⇒ Object
52 53 54 |
# File 'lib/lhs/errors.rb', line 52 def count to_a.size end |
#each ⇒ Object
38 39 40 41 42 |
# File 'lib/lhs/errors.rb', line 38 def each .each_key do |attribute| self[attribute].each { |error| yield attribute, error } end end |
#empty? ⇒ Boolean
56 57 58 |
# File 'lib/lhs/errors.rb', line 56 def empty? all? { |_k, v| v && v.empty? && !v.is_a?(String) } end |
#get(key) ⇒ Object
20 21 22 |
# File 'lib/lhs/errors.rb', line 20 def get(key) [key] end |
#include?(attribute) ⇒ Boolean Also known as: has_key?, key?
14 15 16 |
# File 'lib/lhs/errors.rb', line 14 def include?(attribute) [attribute].present? end |
#set(key, value) ⇒ Object
24 25 26 |
# File 'lib/lhs/errors.rb', line 24 def set(key, value) [key] = value end |
#size ⇒ Object
44 45 46 |
# File 'lib/lhs/errors.rb', line 44 def size values.flatten.size end |