Sha256: bb39a61174f9be9119efe876995cf6e91aa23112efc196b932a47f5eaf98e275

Contents?: true

Size: 971 Bytes

Versions: 1

Compression:

Stored size: 971 Bytes

Contents

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

require 'aequitas/rule/length'

module Aequitas
  class Rule
    class Length
      class Range < Length 

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

        attr_reader :range

        def initialize(attribute_name, options)
          super

          @range = options.fetch(:range)
        end

        def violation_type(resource)
          :length_between
        end

        def violation_data(resource)
          [ [ :min, range.begin ], [ :max, range.end ] ]
        end

        # Validate the value length is within expected range
        #
        # @param [Integer] length
        #   the value length
        #
        # @return [String, NilClass]
        #   the error message if invalid, nil if valid
        #
        # @api private
        def valid_length?(length)
          range.include?(length)
        end

      end # class Range
    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/range.rb