# frozen_string_literal: true module ErpIntegration module Resources # The `ErpIntegration::Resources::Errors` expose a clean, simple API to manage # and display error messages for any `ErpIntegration::Resource` instance. class Errors include Enumerable extend Forwardable def_delegators :@errors, :any?, :blank?, :clear, :count, :empty?, :uniq!, :size def initialize @errors = [] end # Allows adding new error messages to the `ErpIntegration::Resource`. # @param message [String] An (internal/external) error message. # @return [String] The given error message. def add(message) raise ErpIntegration::Error, 'Use a simple string as an error message' unless message.is_a?(String) @errors << message message end def each(&block) @errors.each(&block) end end end end