module ProfanityFilter::ClassMethods

Public Instance Methods

profanity_filter(*attr_names) click to toggle source
# File lib/profanity_filter.rb, line 16
def profanity_filter(*attr_names)
  option = attr_names.pop[:method] if attr_names.last.is_a?(Hash)

  attr_names.each do |attr_name|
    instance_eval do
      define_method "#{attr_name}_clean" do; ProfanityFilter::Base.clean(self[attr_name.to_sym], option); end
      define_method "#{attr_name}_original"do; self[attr_name]; end
      alias_method attr_name.to_sym, "#{attr_name}_clean".to_sym
    end
  end
end
profanity_filter!(*attr_names) click to toggle source
# File lib/profanity_filter.rb, line 11
def profanity_filter!(*attr_names)
  option = attr_names.pop[:method] if attr_names.last.is_a?(Hash)
  attr_names.each { |attr_name| setup_callbacks_for(attr_name, option) }
end
setup_callbacks_for(attr_name, option) click to toggle source
# File lib/profanity_filter.rb, line 28
def setup_callbacks_for(attr_name, option)
  before_validation do |record|
    record[attr_name.to_sym] = ProfanityFilter::Base.clean(record[attr_name.to_sym], option)
  end
end