Sha256: 8d4310cb9a5446ed749d640988e5b63773ee398fc0cbb87931b9bd0d063d261c

Contents?: true

Size: 376 Bytes

Versions: 7

Compression:

Stored size: 376 Bytes

Contents

module Validatable
  class ValidatesExclusionOf < Validatable::ValidationBase
    required_option :within

    def valid?(instance)
      value = instance.send(attribute)
      return true if allow_nil && value.nil?
      return true if allow_blank && value.blank?
      !within.include?(value)
    end

    def message(instance)
      super || "is excluded"
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
durran-validatable-2.0.1 lib/validations/validates_exclusion_of.rb
durran-validatable-2.0.0 lib/validations/validates_exclusion_of.rb
durran-validatable-1.8.4 lib/validations/validates_exclusion_of.rb
durran-validatable-1.8.3 lib/validations/validates_exclusion_of.rb
durran-validatable-1.8.2 lib/validations/validates_exclusion_of.rb
durran-validatable-1.8.1 lib/validations/validates_exclusion_of.rb
durran-validatable-1.8.0 lib/validations/validates_exclusion_of.rb