Module: DataCleansing::Cleanse::InstanceMethods
- Defined in:
- lib/data_cleansing/cleanse.rb
Instance Method Summary collapse
-
#cleanse_attributes!(verbose = DataCleansing.logger.debug?) ⇒ Object
Cleanse the attributes using specified cleaners and execute after cleaners once complete.
Instance Method Details
#cleanse_attributes!(verbose = DataCleansing.logger.debug?) ⇒ Object
Cleanse the attributes using specified cleaners and execute after cleaners once complete
Returns fields changed whilst cleaning the attributes
Note: At this time the changes returned does not include any fields
modified in any of the after_cleaner methods
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/data_cleansing/cleanse.rb', line 134 def cleanse_attributes!(verbose=DataCleansing.logger.debug?) changes = {} DataCleansing.logger.benchmark_info("#{self.class.name}#cleanse_attributes!", :payload => changes) do # Collect parent cleaners first, starting with the top parent cleaners = [self.class.send(:data_cleansing_cleaners)] after_cleaners = [self.class.send(:data_cleansing_after_cleaners)] klass = self.class.superclass while klass != Object cleaners << klass.send(:data_cleansing_cleaners) if klass.respond_to?(:data_cleansing_cleaners) after_cleaners << klass.send(:data_cleansing_after_cleaners) if klass.respond_to?(:data_cleansing_after_cleaners) klass = klass.superclass end # Capture all modified fields if log_level is :debug or :trace cleaners.reverse_each {|cleaner| changes.merge!(data_cleansing_execute_cleaners(cleaner, verbose))} # Execute the after cleaners, starting with the parent after cleanse methods after_cleaners.reverse_each {|a| a.each {|method| send(method)} } end changes end |