Sha256: dbbee385374349b48bf12bee29780432ecefc826de3464058e0b4362bb9a6bca

Contents?: true

Size: 972 Bytes

Versions: 1

Compression:

Stored size: 972 Bytes

Contents

# -*- encoding: utf-8 -*-

require 'aequitas/rule/length'

module Aequitas
  class Rule
    class Length
      class Equal < Length

        equalize_on *superclass.superclass.equalizer.keys + [:expected]

        attr_reader :expected

        def initialize(attribute_name, options)
          super

          @expected = options.fetch(:expected)
        end

        def violation_type(resource)
          :wrong_length
        end

        def violation_data(resource)
          [ [ :expected, expected ] ]
        end

      private

        # Validate the value length is equal to the expected length
        #
        # @param [Integer] length
        #   the value length
        #
        # @return [String, nil]
        #   the error message if invalid, nil if not
        #
        # @api private
        def valid_length?(length)
          expected == length
        end

      end # class Equal
    end # class Length
  end # class Rule
end # module Aequitas

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
aequitas-0.0.2 lib/aequitas/rule/length/equal.rb