Class: Saulabs::Reportable::ReportCache
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Saulabs::Reportable::ReportCache
- Defined in:
- lib/saulabs/reportable/report_cache.rb
Overview
The ReportCache
class is a regular ActiveRecord
model and represents cached results for single ReportingPeriods. ReportCache
instances are identified by the combination of model_class_name
, report_name
, grouping
, aggregation
and reporting_period
.
Class Method Summary collapse
-
.clear_for(klass, report) ⇒ Object
Clears the cache for the specified
klass
andreport
. -
.process(report, options, &block) ⇒ ResultSet<Array<DateTime, Float>>
Processes the report using the respective cache.
Class Method Details
.clear_for(klass, report) ⇒ Object
Clears the cache for the specified klass
and report
42 43 44 |
# File 'lib/saulabs/reportable/report_cache.rb', line 42 def self.clear_for(klass, report) self.where(model_class_name: klass.name, report_name: report.to_s).delete_all end |
.process(report, options, &block) ⇒ ResultSet<Array<DateTime, Float>>
Processes the report using the respective cache.
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/saulabs/reportable/report_cache.rb', line 67 def self.process(report, , &block) raise ArgumentError.new('A block must be given') unless block_given? # If end_date is in the middle of the current reporting period it means it requests live_data. # Update the options hash to reflect reality. current_reporting_period = ReportingPeriod.new([:grouping]) if [:end_date] && [:end_date] > current_reporting_period.date_time [:live_data] = true .delete(:end_date) end self.transaction do cached_data = read_cached_data(report, ) new_data = read_new_data(cached_data, , &block) prepare_result(new_data, cached_data, report, ) end end |