Module: Strobe::Validations::ClassMethods

Defined in:
lib/strobe/validations.rb

Instance Method Summary collapse

Instance Method Details

#validates(*attrs) ⇒ Object


37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/strobe/validations.rb', line 37

def validates(*attrs)
  attrs.map! do |key|
    key = key.to_sym if key.is_a?(String)
    key
  end

  if Hash === attrs.last
    defaults = attrs.pop
    options  = defaults.slice!(:skippable, :if, :unless, :on, :allow_blank, :allow_nil)

    if Symbol === options[:with]
      options[:with] = { :method => options[:with] }
    end

    if defaults.key?(:skippable)
      options.keys.each do |key|
        value        = _parse_validates_options(options[key])
        options[key] = value.merge(:skippable => defaults[:skippable])
      end

      defaults.delete(:skippable)
    end

    attrs << defaults.merge(options)
  end

  super
end