Sha256: eac608dd913fc374cccc7756857d4b9245f2a19799da63b79bf809dade5884ca

Contents?: true

Size: 380 Bytes

Versions: 7

Compression:

Stored size: 380 Bytes

Contents

module Validatable
  class ValidatesInclusionOf < 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 not included"
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

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