Sha256: c123d64be16c725701afe57fe0d8023866bc00dee23e99065747e5299165a93f

Contents?: true

Size: 689 Bytes

Versions: 3

Compression:

Stored size: 689 Bytes

Contents

module Ohm
  module LengthValidations

    def assert_min_length(att, length, error = [att, :too_short])
      if assert_present(att, error)
        m = send(att).to_s
        assert is_long_enough?(m, length), error
      end
    end

    def assert_max_length(att, length, error = [att, :too_long])
      if assert_present(att, error)
        m = send(att).to_s
        assert is_too_long?(m, length), error
      end
    end

    private
    def is_too_long?(string, length)
      string.size <= length
    rescue ArgumentError
      return false
    end

    def is_long_enough?(string, length)
      string.size >= length
    rescue ArgumentError
      return false
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ohm-contrib-0.0.31 lib/ohm/contrib/length_validations.rb
ohm-contrib-0.0.30 lib/ohm/contrib/length_validations.rb
ohm-contrib-0.0.29 lib/ohm/contrib/length_validations.rb