Module: ProfanityFilter::ClassMethods
- Defined in:
- lib/fu-fu/profanity_filter.rb
Instance Method Summary collapse
- #profanity_filter(*attr_names) ⇒ Object
- #profanity_filter!(*attr_names) ⇒ Object
- #setup_callbacks_for(attr_name, option) ⇒ Object
Instance Method Details
#profanity_filter(*attr_names) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/fu-fu/profanity_filter.rb', line 12 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) ⇒ Object
7 8 9 10 |
# File 'lib/fu-fu/profanity_filter.rb', line 7 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) ⇒ Object
24 25 26 27 28 |
# File 'lib/fu-fu/profanity_filter.rb', line 24 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 |