Class: Lutaml::Model::Errors
- Inherits:
-
Object
- Object
- Lutaml::Model::Errors
- Includes:
- Enumerable
- Defined in:
- lib/lutaml/model/errors.rb
Instance Method Summary collapse
- #add(attr, error) ⇒ Object
- #each ⇒ Object
- #empty? ⇒ Boolean
- #full_messages ⇒ Object
-
#initialize ⇒ Errors
constructor
A new instance of Errors.
- #messages ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize ⇒ Errors
Returns a new instance of Errors.
8 9 10 |
# File 'lib/lutaml/model/errors.rb', line 8 def initialize @errors = {} end |
Instance Method Details
#add(attr, error) ⇒ Object
12 13 14 15 |
# File 'lib/lutaml/model/errors.rb', line 12 def add(attr, error) @errors[attr] ||= [] @errors[attr] << error end |
#each ⇒ Object
21 22 23 |
# File 'lib/lutaml/model/errors.rb', line 21 def each(&) @errors.each(&) end |
#empty? ⇒ Boolean
17 18 19 |
# File 'lib/lutaml/model/errors.rb', line 17 def empty? @errors.empty? end |
#full_messages ⇒ Object
25 26 27 |
# File 'lib/lutaml/model/errors.rb', line 25 def @errors.map { |attr, errors| "#{attr}: #{errors.join(', ')}" } end |
#messages ⇒ Object
29 30 31 |
# File 'lib/lutaml/model/errors.rb', line 29 def @errors.map { |_, errors| errors.join(", ") }.flatten end |
#to_s ⇒ Object
33 34 35 |
# File 'lib/lutaml/model/errors.rb', line 33 def to_s .join("\n") end |