Class: BookmarkStat
- Inherits:
-
ApplicationRecord
- Object
- ApplicationRecord
- BookmarkStat
- Includes:
- CalculateStat, Statesman::Adapters::ActiveRecordQueries
- Defined in:
- app/models/bookmark_stat.rb
Instance Method Summary collapse
Instance Method Details
#calculate_count! ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'app/models/bookmark_stat.rb', line 20 def calculate_count! self.started_at = Time.zone.now Manifestation.find_each do |manifestation| daily_count = Bookmark.manifestations_count(start_date, end_date, manifestation) # manifestation.update_attributes({:daily_bookmarks_count => daily_count, :total_count => manifestation.total_count + daily_count}) if daily_count > 0 self.manifestations << manifestation sql = ['UPDATE bookmark_stat_has_manifestations SET bookmarks_count = ? WHERE bookmark_stat_id = ? AND manifestation_id = ?', daily_count, self.id, manifestation.id] ActiveRecord::Base.connection.execute( self.class.send(:sanitize_sql_array, sql) ) end end self.completed_at = Time.zone.now transition_to!(:completed) end |
#state_machine ⇒ Object
13 14 15 |
# File 'app/models/bookmark_stat.rb', line 13 def state_machine BookmarkStatStateMachine.new(self, transition_class: BookmarkStatTransition) end |