Module: ProfanityFilter::ClassMethods
- Defined in:
- lib/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
16 17 18 19 20 21 22 23 24 25 26 |
# 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) ⇒ Object
11 12 13 14 |
# 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) ⇒ Object
28 29 30 31 32 |
# 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 |