Class: ChefAPI::ErrorCollection

Inherits:
Hash
  • Object
show all
Defined in:
lib/chef-api/error_collection.rb

Overview

Private internal class for managing the error collection.

Instance Method Summary collapse

Constructor Details

#initializeProc

The default proc for the hash needs to be an empty Array.



11
12
13
# File 'lib/chef-api/error_collection.rb', line 11

def initialize
  super { |h, k| h[k] = [] }
end

Instance Method Details

#add(key, error) ⇒ self

Add a new error to the hash.

Parameters:

  • key (Symbol)

    the attribute key

  • error (String)

    the error message to push

Returns:

  • (self)


25
26
27
28
# File 'lib/chef-api/error_collection.rb', line 25

def add(key, error)
  self[key].push(error)
  self
end

#full_messagesArray<String>

Output the full messages for each error. This is useful for displaying information about validation to the user when something goes wrong.

Returns:

  • (Array<String>)


36
37
38
39
40
41
42
# File 'lib/chef-api/error_collection.rb', line 36

def full_messages
  map do |key, errors|
    errors.map do |error|
      "`#{key}' #{error}"
    end
  end.flatten
end