Sha256: 5bf9f9d3923450c1611baac1a641c097b66208052a65805288c2c344fdd13098

Contents?: true

Size: 948 Bytes

Versions: 1

Compression:

Stored size: 948 Bytes

Contents

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

require 'aequitas/rule/length'

module Aequitas
  class Rule
    class Length
      class Maximum < Length

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

        attr_reader :bound

        def initialize(attribute_name, options)
          super

          @bound = options.fetch(:bound)
        end

        def violation_type(resource)
          :too_long
        end

        def violation_data(resource)
          [ [ :maximum, bound ] ]
        end

        # Validate the value length is less than or equal to the bound
        #
        # @param [Integer] length
        #   the value length
        #
        # @return [String, NilClass]
        #   the error message if invalid, nil if valid
        #
        # @api private
        def valid_length?(length)
          bound >= length
        end

      end # class Maximum
    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/maximum.rb