Class: Timeseries
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Timeseries
- Defined in:
- lib/generators/rails_timeseries/install/templates/timeseries.rb
Class Method Summary collapse
Class Method Details
.data(scope, options = {}) ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/generators/rails_timeseries/install/templates/timeseries.rb', line 14 def self.data(scope, = {}) .symbolize_keys! data = where(scope: scope) data = data.where('date > ?', [:start_date]) if [:start_date] data = data.where('date < ?', [:end_date]) if [:end_date] data = data.order(:date).pluck(:date, :count) Hash[data] end |
.generate ⇒ Object
2 3 4 5 6 7 8 9 10 11 12 |
# File 'lib/generators/rails_timeseries/install/templates/timeseries.rb', line 2 def self.generate ActiveRecord::Base.subclasses.each do |model| next unless model.respond_to?(:timeseries_scopes) model.send(:timeseries_scopes).each do |scope| timeseries = Timeseries.find_or_initialize_by(date: Time.now.to_date, scope: scope.to_s) timeseries.count = model.send(scope).count timeseries.save end end return end |