Module: ValidatesDecencyOf::ClassMethods

Defined in:
lib/validates_decency_of.rb

Instance Method Summary collapse

Instance Method Details

#validates_decency_of(*attribute_names) ⇒ Object

Uses George Carlin’s list of “seven dirty words” to “check for decency” (ahem) en.wikipedia.org/wiki/Seven_dirty_words Future versions will support adding/removing from this list Ex:

class Message < ActiveRecord::Base

validates_decency_of :title, :description

end

Configuration Options

:message

A custom error message (default is: “is invalid”)



20
21
22
23
24
25
26
27
# File 'lib/validates_decency_of.rb', line 20

def validates_decency_of(*attribute_names)
  options = { :message => 'is invalid' }
  options.merge!(attribute_names.pop) if attribute_names.last.kind_of?(Hash)
  options.merge! :on => :save
  validates_each(attribute_names, options) do |record, attribute_name, value|
    record.errors.add attribute_name, options[:message] unless value.to_s.is_decent?
  end
end