Sha256: eb86428b0e92dab7f484f15e71540cdc204cb7970d54fbbf5e8c9fcdb058457e

Contents?: true

Size: 903 Bytes

Versions: 49

Compression:

Stored size: 903 Bytes

Contents

# 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

Version data entries

49 entries across 49 versions & 1 rubygems

Version Path
erp_integration-0.57.0 lib/erp_integration/resources/errors.rb
erp_integration-0.56.0 lib/erp_integration/resources/errors.rb
erp_integration-0.55.0 lib/erp_integration/resources/errors.rb
erp_integration-0.54.0 lib/erp_integration/resources/errors.rb
erp_integration-0.53.1 lib/erp_integration/resources/errors.rb
erp_integration-0.53.0 lib/erp_integration/resources/errors.rb
erp_integration-0.52.0 lib/erp_integration/resources/errors.rb
erp_integration-0.50.0 lib/erp_integration/resources/errors.rb
erp_integration-0.49.0 lib/erp_integration/resources/errors.rb
erp_integration-0.48.0 lib/erp_integration/resources/errors.rb
erp_integration-0.43.0 lib/erp_integration/resources/errors.rb
erp_integration-0.42.0 lib/erp_integration/resources/errors.rb
erp_integration-0.41.0 lib/erp_integration/resources/errors.rb
erp_integration-0.40.0 lib/erp_integration/resources/errors.rb
erp_integration-0.39.0 lib/erp_integration/resources/errors.rb
erp_integration-0.38.0 lib/erp_integration/resources/errors.rb
erp_integration-0.37.0 lib/erp_integration/resources/errors.rb
erp_integration-0.36.1 lib/erp_integration/resources/errors.rb
erp_integration-0.36.0 lib/erp_integration/resources/errors.rb
erp_integration-0.35.0 lib/erp_integration/resources/errors.rb