Sha256: e0802fac6ec05e58e3b85fa5f68911d4d3749aa4387adb872b1a3c9fedb37f16
Contents?: true
Size: 932 Bytes
Versions: 3
Compression:
Stored size: 932 Bytes
Contents
# frozen_string_literal: true require "key_vortex/constraint/base" class KeyVortex module Constraint # Enforces that objects which respond to #length less than the # specified limit. class Length < KeyVortex::Constraint::Base # @return [Integer] The upper bound allowed when calling #length on a value attr_reader :limit # @param limit [Integer] The maximum allowed value def initialize(limit) super() @limit = limit end # @return [Symbol] :length def attribute :length end # @param constraint [Length] # @return [Boolean] True if limit <= constraint.limit def within?(constraint) super && limit <= constraint.limit end # @param value [Object] Must respond to #length # @return [Boolean] True if length <= limit def accepts?(value) value.length <= limit end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
key-vortex-1.1.1 | lib/key_vortex/constraint/length.rb |
key-vortex-1.1.0 | lib/key_vortex/constraint/length.rb |
key-vortex-1.0.0 | lib/key_vortex/constraint/length.rb |