module ActiveCleaner

ActiveCleaner

See HelperMethods for the DSL.

Example

class Post
  include Mongoid::Document
  include ActiveCleaner

  field :title
  field :subtitle
  clean :title, :subtitle, nilify: true

  field :body
  clean :body, as: :text, nilify: true
end

Public Instance Methods

read_attribute_for_cleaning(attr_name) click to toggle source

Method used by the cleaners to read the value of an attribute.

# File lib/active_cleaner.rb, line 76
def read_attribute_for_cleaning(attr_name)
  send(attr_name)
end
run_cleaners!() click to toggle source

Do run the cleaners

# File lib/active_cleaner.rb, line 65
def run_cleaners!
  _cleaners.each do |_attr_name, cleaners|
    cleaners.each do |cleaner|
      cleaner.clean(self)
    end
  end

  true
end
write_attribute_after_cleaning(attr_name, value) click to toggle source

Method used by the cleaners to write the value of an attribute.

# File lib/active_cleaner.rb, line 81
def write_attribute_after_cleaning(attr_name, value)
  send(:"#{attr_name}=", value)
end