Module: Mongo::Voteable::Tasks
- Defined in:
- lib/voteable_mongo/tasks.rb
Class Method Summary collapse
-
.init_stats(log = false) ⇒ Object
Set counters and point to 0 for uninitialized voteable objects in order sort and query.
-
.migrate_old_votes(log = false) ⇒ Object
Convert votes from from version < 0.7.0 to new data store.
-
.remake_stats(log = false) ⇒ Object
Re-generate vote counters and vote points.
Class Method Details
.init_stats(log = false) ⇒ Object
Set counters and point to 0 for uninitialized voteable objects in order sort and query
7 8 9 10 11 12 13 14 |
# File 'lib/voteable_mongo/tasks.rb', line 7 def self.init_stats(log = false) VOTEABLE.each do |class_name, voteable| klass = class_name.constantize klass_voteable = voteable[class_name] puts "Init stats for #{class_name}" if log klass.with(safe: true).where(votes: nil).update_all({ '$set' => {votes: DEFAULT_VOTES} }) end end |
.migrate_old_votes(log = false) ⇒ Object
Convert votes from from version < 0.7.0 to new data store
23 24 25 26 27 28 29 30 |
# File 'lib/voteable_mongo/tasks.rb', line 23 def self.migrate_old_votes(log = false) VOTEABLE.each do |class_name, voteable| klass = class_name.constantize klass_voteable = voteable[class_name] puts "* Migrating old vote data for #{class_name} ..." if log migrate_old_votes_for(klass, klass_voteable) end end |
.remake_stats(log = false) ⇒ Object
Re-generate vote counters and vote points
17 18 19 20 |
# File 'lib/voteable_mongo/tasks.rb', line 17 def self.remake_stats(log = false) remake_stats_for_all_voteable_classes(log) update_parent_stats(log) end |