lib/counter_culture/extensions.rb
# checks all of the declared counter caches on this class for correctnes based
# on original data; if the counter cache is incorrect, sets it to the correct
# count
#
# options:
#   { :exclude => list of relations to skip when fixing counts,
#     :only => only these relations will have their counts fixed }
# returns: a list of fixed record as an array of hashes of the form:
#   { :entity => which model the count was fixed on,
#     :id => the id of the model that had the incorrect count,
#     :what => which column contained the incorrect count,
#     :wrong => the previously saved, incorrect count,
#     :right => the newly fixed, correct count }
#
checks all of the declared counter caches on this class for correctnes based
on original data; if the counter cache is incorrect, sets it to the correct
count


checks all of the declared counter caches on this class for correctnes based on original data ; if the counter cache is incorrect sets it to the correct count
def counter_culture_fix_counts(options = {})
        raise "No counter cache defined on #{name}" unless @after_commit_counter_cache
        options[:exclude] = Array(options[:exclude]) if options[:exclude]
        options[:exclude] = options[:exclude].try(:map) {|x| x.is_a?(Enumerable) ? x : [x] }
        options[:only] = [options[:only]] if options[:only] && !options[:only].is_a?(Enumerable)
        options[:only] = options[:only].try(:map) {|x| x.is_a?(Enumerable) ? x : [x] }
        @after_commit_counter_cache.flat_map do |counter|
          next if options[:exclude] && options[:exclude].include?(counter.relation)
          next if options[:only] && !options[:only].include?(counter.relation)
          reconciler = CounterCulture::Reconciler.new(counter, options.slice(:skip_unsupported, :batch_size, :touch, :where, :verbose))
          reconciler.reconcile!
          reconciler.changes
        end.compact
      end
def counter_culture_fix_counts ( options = { } ) raise "No counter cache defined on #{name}" unless @after_commit_counter_cache options [ :exclude ] = Array ( options [ :exclude ] ) if options [ :exclude ] options [ :exclude ] = options [ :exclude ] . try ( :map ) { | x | x . is_a? ( Enumerable ) ? x : [ x ] } options [ :only ] = [ options [ :only ] ] if options [ :only ] && ! options [ :only ] . is_a? ( Enumerable ) options [ :only ] = options [ :only ] . try ( :map ) { | x | x . is_a? ( Enumerable ) ? x : [ x ] } @after_commit_counter_cache . flat_map do | counter | next if options [ :exclude ] && options [ :exclude ] . include? ( counter . relation ) next if options [ :only ] && ! options [ :only ] . include? ( counter . relation ) reconciler = CounterCulture :: Reconciler . new ( counter , options . slice ( :skip_unsupported , :batch_size , :touch , :where , :verbose ) ) reconciler . reconcile! reconciler . changes end . compact end
checks all of the declared counter caches on this class for correctnes based
on original data; if the counter cache is incorrect, sets it to the correct
count
checks all of the declared counter caches on this class for correctnes based on original data ; if the counter cache is incorrect sets it to the correct count
options
<not_specific>