Class: SexyValidations::Validators::Inclusion

Inherits:
Object
  • Object
show all
Defined in:
lib/sexy_validations/validators/inclusion.rb

Class Method Summary collapse

Class Method Details

.validate(model, attribute, value, options) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/sexy_validations/validators/inclusion.rb', line 5

def self.validate(model, attribute, value, options)
  return unless value

  unless options.is_a?(Hash)
    options = {
      :within => options,
    }
  end
  
  data = case options[:within]
    when Proc
      options[:within].call(model)
    else
      options[:within]
  end

  unless data.include?(value)
    model.errors.add(attribute, options[:message] || "ungültige Auswahl")
  end
end