Sha256: 4be6ed2445cd6968e0c2eca901dcb4385439dceb30af603dff011bb81fb0fa1e
Contents?: true
Size: 1.05 KB
Versions: 1
Compression:
Stored size: 1.05 KB
Contents
# Uses George Carlin's list of "seven dirty words" to "check for decency" (ahem) # http://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 # # [<tt>:message</tt>] A custom error message (default is: "is invalid") # module ValidatesDecencyOf INDECENT_WORDS = %w(shit piss fuck cunt cocksucker motherfucker tits) def self.indecent?(str) essence = str.to_s.downcase.gsub /[^\.\'a-zA-Z]/, '' INDECENT_WORDS.any? { |c| essence.include? c } end 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] if ValidatesDecencyOf.indecent? value end end end ActiveRecord::Base.extend ValidatesDecencyOf
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
validates_decency_of-1.5.0 | lib/validates_decency_of.rb |