Class: UserReserveStat
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- UserReserveStat
- Includes:
- CalculateStat, Statesman::Adapters::ActiveRecordQueries
- Defined in:
- app/models/user_reserve_stat.rb
Instance Attribute Summary collapse
-
#mode ⇒ Object
Returns the value of attribute mode.
Instance Method Summary collapse
Instance Attribute Details
#mode ⇒ Object
Returns the value of attribute mode.
11 12 13 |
# File 'app/models/user_reserve_stat.rb', line 11 def mode @mode end |
Instance Method Details
#calculate_count! ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'app/models/user_reserve_stat.rb', line 22 def calculate_count! self.started_at = Time.zone.now User.find_each do |user| daily_count = user.reserves.created(start_date.beginning_of_day, end_date.tomorrow.beginning_of_day).size if daily_count > 0 self.users << user sql = ['UPDATE reserve_stat_has_users SET reserves_count = ? WHERE user_reserve_stat_id = ? AND user_id = ?', daily_count, id, user.id] UserReserveStat.connection.execute( self.class.send(:sanitize_sql_array, sql) ) end end self.completed_at = Time.zone.now transition_to!(:completed) end |
#state_machine ⇒ Object
15 16 17 |
# File 'app/models/user_reserve_stat.rb', line 15 def state_machine UserReserveStatStateMachine.new(self, transition_class: UserReserveStatTransition) end |