Class: SecID::Errors
- Inherits:
-
Object
- Object
- SecID::Errors
- Defined in:
- lib/sec_id/errors.rb
Overview
Instance Attribute Summary collapse
-
#details ⇒ Array<Hash{Symbol => Symbol, String}>
readonly
Array of error hashes with :error and :message keys.
Instance Method Summary collapse
-
#any? ⇒ Boolean
True when there are errors.
-
#as_json ⇒ Array<Hash>
Returns a JSON-compatible array of error detail hashes.
-
#each {|detail| ... } ⇒ Enumerator, self
Yields each error detail hash to the block.
-
#empty? ⇒ Boolean
(also: #none?)
True when there are no errors.
-
#initialize(errors) ⇒ Errors
constructor
A new instance of Errors.
-
#messages ⇒ Array<String>
Human-readable error messages.
-
#size ⇒ Integer
Number of errors.
-
#to_a ⇒ Array<String>
Alias for #messages.
Constructor Details
#initialize(errors) ⇒ Errors
Returns a new instance of Errors.
25 26 27 28 |
# File 'lib/sec_id/errors.rb', line 25 def initialize(errors) @details = errors.freeze freeze end |
Instance Attribute Details
#details ⇒ Array<Hash{Symbol => Symbol, String}> (readonly)
Returns array of error hashes with :error and :message keys.
22 23 24 |
# File 'lib/sec_id/errors.rb', line 22 def details @details end |
Instance Method Details
#any? ⇒ Boolean
Returns true when there are errors.
36 37 38 |
# File 'lib/sec_id/errors.rb', line 36 def any? !@details.empty? end |
#as_json ⇒ Array<Hash>
Returns a JSON-compatible array of error detail hashes.
70 71 72 |
# File 'lib/sec_id/errors.rb', line 70 def as_json(*) details end |
#each {|detail| ... } ⇒ Enumerator, self
Yields each error detail hash to the block.
58 59 60 |
# File 'lib/sec_id/errors.rb', line 58 def each(&) @details.each(&) end |
#empty? ⇒ Boolean Also known as: none?
Returns true when there are no errors.
41 42 43 |
# File 'lib/sec_id/errors.rb', line 41 def empty? @details.empty? end |
#messages ⇒ Array<String>
Returns human-readable error messages.
31 32 33 |
# File 'lib/sec_id/errors.rb', line 31 def @details.map { |e| e[:message] } end |
#size ⇒ Integer
Returns number of errors.
50 51 52 |
# File 'lib/sec_id/errors.rb', line 50 def size @details.size end |
#to_a ⇒ Array<String>
Returns alias for #messages.
63 64 65 |
# File 'lib/sec_id/errors.rb', line 63 def to_a end |