Class: SimplyStored::Couch::Validations::ValidatesInclusionOf

Inherits:
Validatable::ValidationBase
  • Object
show all
Defined in:
lib/simply_stored/couch/validations.rb

Instance Method Summary collapse

Instance Method Details

#message(instance) ⇒ Object



20
21
22
# File 'lib/simply_stored/couch/validations.rb', line 20

def message(instance)
  super || "must be one or more of #{self.in.join(", ")}"
end

#valid?(instance) ⇒ Boolean

Returns:

  • (Boolean)


8
9
10
11
12
13
14
15
16
17
18
# File 'lib/simply_stored/couch/validations.rb', line 8

def valid?(instance)
  if self.allow_blank && instance.send(attribute).blank?
    true
  else
    values = instance.send(attribute)
    values = [values] unless values.is_a?(Array)
    values.select{|value|
      !self.in.include?(value)
    }.empty?
  end
end