Sha256: ab8d3d3b604e5a28eac0f6309098d0d40e2a45decf101c718a84ce40648e67ec

Contents?: true

Size: 1.48 KB

Versions: 5

Compression:

Stored size: 1.48 KB

Contents

module Lotus
  module Validations
    # A single validation error for an attribute
    #
    # @since 0.1.0
    class Error
      # The name of the attribute
      #
      # @return [Symbol] the name of the attribute
      #
      # @since 0.1.0
      attr_reader :attribute

      # The name of the validation
      #
      # @return [Symbol] the name of the validation
      #
      # @since 0.1.0
      attr_reader :validation

      # The expected value
      #
      # @return [Object] the expected value
      #
      # @since 0.1.0
      attr_reader :expected

      # The actual value
      #
      # @return [Object] the actual value
      #
      # @since 0.1.0
      attr_reader :actual

      # Initialize a validation error
      #
      # @param attribute [Symbol] the name of the attribute
      # @param validation [Symbol] the name of the validation
      # @param expected [Object] the expected value
      # @param actual [Object] the actual value
      #
      # @since 0.1.0
      # @api private
      def initialize(attribute, validation, expected, actual)
        @attribute, @validation, @expected, @actual =
          attribute, validation, expected, actual
      end

      # Check if self equals to `other`
      #
      # @since 0.1.0
      def ==(other)
        other.is_a?(self.class) &&
          other.attribute  == attribute  &&
          other.validation == validation &&
          other.expected   == expected   &&
          other.actual     == actual
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
lotus-validations-0.2.3 lib/lotus/validations/error.rb
lotus-validations-0.2.2 lib/lotus/validations/error.rb
lotus-validations-0.2.1 lib/lotus/validations/error.rb
lotus-validations-0.2.0 lib/lotus/validations/error.rb
lotus-validations-0.1.0 lib/lotus/validations/error.rb