Class: Lutaml::Model::Errors

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/lutaml/model/errors.rb

Instance Method Summary collapse

Constructor Details

#initializeErrors

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

#eachObject



21
22
23
# File 'lib/lutaml/model/errors.rb', line 21

def each(&)
  @errors.each(&)
end

#empty?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/lutaml/model/errors.rb', line 17

def empty?
  @errors.empty?
end

#full_messagesObject



25
26
27
# File 'lib/lutaml/model/errors.rb', line 25

def full_messages
  @errors.map { |attr, errors| "#{attr}: #{errors.join(', ')}" }
end

#messagesObject



29
30
31
# File 'lib/lutaml/model/errors.rb', line 29

def messages
  @errors.map { |_, errors| errors.join(", ") }.flatten
end

#to_sObject



33
34
35
# File 'lib/lutaml/model/errors.rb', line 33

def to_s
  full_messages.join("\n")
end