Sha256: 69f13134a65bf59666429557bc2965b16f6df1709e7a4616941dc24fc85ead36
Contents?: true
Size: 1.77 KB
Versions: 2
Compression:
Stored size: 1.77 KB
Contents
class BookmarkStat < ActiveRecord::Base include Statesman::Adapters::ActiveRecordModel include CalculateStat attr_accessible :start_date, :end_date, :note default_scope order: 'id DESC' scope :not_calculated, -> {in_state(:pending)} has_many :bookmark_stat_has_manifestations has_many :manifestations, through: :bookmark_stat_has_manifestations paginates_per 10 has_many :bookmark_stat_transitions def state_machine BookmarkStatStateMachine.new(self, transition_class: BookmarkStatTransition) end delegate :can_transition_to?, :transition_to!, :transition_to, :current_state, to: :state_machine 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 private def self.transition_class BookmarkStatTransition end end # == Schema Information # # Table name: bookmark_stats # # id :integer not null, primary key # start_date :datetime # end_date :datetime # started_at :datetime # completed_at :datetime # note :text # created_at :datetime not null # updated_at :datetime not null #
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
enju_bookmark-0.1.2.pre16 | app/models/bookmark_stat.rb |
enju_bookmark-0.1.2.pre15 | app/models/bookmark_stat.rb |