Module: ActiveCleaner

Extended by:
ActiveSupport::Concern
Defined in:
lib/active_cleaner.rb,
lib/active_cleaner/version.rb,
lib/active_cleaner/base_cleaner.rb,
lib/active_cleaner/text_cleaner.rb,
lib/active_cleaner/helper_methods.rb,
lib/active_cleaner/string_cleaner.rb,
lib/active_cleaner/utf8mb3_cleaner.rb,
lib/active_cleaner/markdown_cleaner.rb

Overview

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

Defined Under Namespace

Modules: ClassMethods, HelperMethods, Version Classes: BaseCleaner, MarkdownCleaner, StringCleaner, TextCleaner, Utf8mb3Cleaner

Instance Method Summary collapse

Instance Method Details

#read_attribute_for_cleaning(attr_name) ⇒ Object

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



76
77
78
# File 'lib/active_cleaner.rb', line 76

def read_attribute_for_cleaning(attr_name)
  send(attr_name)
end

#run_cleaners!Object

Do run the cleaners



65
66
67
68
69
70
71
72
73
# 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) ⇒ Object

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



81
82
83
# File 'lib/active_cleaner.rb', line 81

def write_attribute_after_cleaning(attr_name, value)
  send(:"#{attr_name}=", value)
end