Sha256: de99080cf7c0901d1b65f230fd9b8a2075d9e16280eee8b2b7a189f3690ecb3f

Contents?: true

Size: 907 Bytes

Versions: 14

Compression:

Stored size: 907 Bytes

Contents

module ChefAPI
  #
  # Private internal class for managing the error collection.
  #
  class ErrorCollection < Hash
    #
    # The default proc for the hash needs to be an empty Array.
    #
    # @return [Proc]
    #
    def initialize
      super { |h, k| h[k] = [] }
    end

    #
    # Add a new error to the hash.
    #
    # @param [Symbol] key
    #   the attribute key
    # @param [String] error
    #   the error message to push
    #
    # @return [self]
    #
    def add(key, error)
      self[key].push(error)
      self
    end

    #
    # Output the full messages for each error. This is useful for displaying
    # information about validation to the user when something goes wrong.
    #
    # @return [Array<String>]
    #
    def full_messages
      self.map do |key, errors|
        errors.map do |error|
          "`#{key}' #{error}"
        end
      end.flatten
    end
  end
end

Version data entries

14 entries across 14 versions & 2 rubygems

Version Path
chef-infra-api-0.10.0 lib/chef-api/error_collection.rb
chef-api-0.10.0 lib/chef-api/error_collection.rb
chef-infra-api-0.9.1 lib/chef-api/error_collection.rb
chef-api-0.9.0 lib/chef-api/error_collection.rb
chef-api-0.8.0 lib/chef-api/error_collection.rb
chef-api-0.7.1 lib/chef-api/error_collection.rb
chef-api-0.7.0 lib/chef-api/error_collection.rb
chef-api-0.6.0 lib/chef-api/error_collection.rb
chef-api-0.5.0 lib/chef-api/error_collection.rb
chef-api-0.4.1 lib/chef-api/error_collection.rb
chef-api-0.4.0 lib/chef-api/error_collection.rb
chef-api-0.3.0 lib/chef-api/error_collection.rb
chef-api-0.2.1 lib/chef-api/error_collection.rb
chef-api-0.2.0 lib/chef-api/error_collection.rb