Sha256: 55bcf5fd4a3f3e1d79ca7ba0cd4b765846cd0e6382f608cfec2d736c3851f0e2

Contents?: true

Size: 1015 Bytes

Versions: 3

Compression:

Stored size: 1015 Bytes

Contents

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

require 'data_mapper/validation/rule/length'

module DataMapper
  module Validation
    class Rule
      module Length

        class Equal < Rule

          include Length

          def initialize(attribute_name, options)
            super

            @expected = options.fetch(:equal)
          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 # module Length
    end # class Rule
  end # module Validation
end # module DataMapper

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
sbf-dm-validations-1.4.0 lib/data_mapper/validation/rule/length/equal.rb
sbf-dm-validations-1.3.0 lib/data_mapper/validation/rule/length/equal.rb
sbf-dm-validations-1.3.0.beta lib/data_mapper/validation/rule/length/equal.rb