Sha256: 360810edbea6806c14187272065e0947b5758d1f6842f88d5fefaa17219fc137
Contents?: true
Size: 555 Bytes
Versions: 1
Compression:
Stored size: 555 Bytes
Contents
# frozen_string_literal: true module SimpleValidate class ValidatesInclusionOf < ValidatesBase def initialize(attribute, options) @set = options[:in] @allow_nil = options[:allow_nil] raise ArgumentError unless [Array, Range].include?(@set.class) super(attribute, options[:message] || "breaks inclusion rules", options[:if] || proc { true }) end def valid?(instance) val = instance.send(attribute) return true if val.nil? && @allow_nil == true @set.to_a.include?(val) end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
simple_validate-2.2.2 | lib/simple_validate/validates_inclusion_of.rb |