Introduction
Introduction Statistics Contact Development Disclaimer Help
Adds :cacheable option to report/report_cache/spec - reportable - Fork of repor…
Log
Files
Refs
README
---
commit 75d20a8cac2c0cfbb2bcdc525d689d00ddaff00c
parent 0df483b8bc4873c284acd75126d8c016355ebab5
Author: HD Moore <[email protected]>
Date: Sat, 12 Jan 2013 20:40:26 -0600
Adds :cacheable option to report/report_cache/spec
Diffstat:
M lib/saulabs/reportable/report.rb | 10 ++++++++--
M lib/saulabs/reportable/report_cach… | 14 ++++++++++----
M spec/classes/report_spec.rb | 6 +++---
3 files changed, 21 insertions(+), 9 deletions(-)
---
diff --git a/lib/saulabs/reportable/report.rb b/lib/saulabs/reportable/report.rb
@@ -58,6 +58,8 @@ module Saulabs
# specifies whether data for the current reporting period is to be rea…
# @option options [DateTime, Boolean] :end_date (false)
# when specified, the report will only include data for the +:limit+ r…
+ # @option options [Boolean] :cacheable (true)
+ # when set to false, the report will never use the cache, which allows…
#
def initialize(klass, name, options = {})
ensure_valid_options(options)
@@ -72,7 +74,8 @@ module Saulabs
:conditions => options[:conditions] || [],
:grouping => Grouping.new(options[:grouping] || :day),
:live_data => options[:live_data] || false,
- :end_date => options[:end_date] || false
+ :end_date => options[:end_date] || false,
+ :cacheable => ( options[:cacheable] == false ? false : true )
}
@options.merge!(options)
@options.freeze
@@ -94,6 +97,9 @@ module Saulabs
# @option options [DateTime, Boolean] :end_date (false)
# when specified, the report will only include data for the +:limit+ r…
#
+ # @option options [Boolean] :cacheable (true)
+ # when set to false, the report will never use the cache, which allows…
+ #
# @return [Array<Array<DateTime, Float>>]
# the result of the report as pairs of {DateTime}s and {Float}s
#
@@ -147,7 +153,7 @@ module Saulabs
case context
when :initialize
options.each_key do |k|
- raise ArgumentError.new("Invalid option #{k}!") unless [:limit…
+ raise ArgumentError.new("Invalid option #{k}!") unless [:limit…
end
raise ArgumentError.new("Invalid aggregation #{options[:aggregat…
raise ArgumentError.new('The name of the column holding the valu…
diff --git a/lib/saulabs/reportable/report_cache.rb b/lib/saulabs/reportable/re…
@@ -63,6 +63,8 @@ module Saulabs
# specifies whether data for the current reporting period is to be rea…
# @option options [DateTime, Boolean] :end_date (false)
# when specified, the report will only include data for the +:limit+ r…
+ # @option options [Boolean] :cacheable (true)
+ # when set to false, the report will never use the cache, which allows…
#
# @return [ResultSet<Array<DateTime, Float>>]
# the result of the report as pairs of {DateTime}s and {Float}s
@@ -94,12 +96,15 @@ module Saulabs
reporting_period = get_first_reporting_period(options)
result = []
while reporting_period < (options[:end_date] ? ReportingPeriod.new(o…
- if cached = cached_data.find { |cached| reporting_period == cached…
+ if options[:cacheable] and cached = cached_data.find { |cached| re…
result << [cached[0].date_time, cached[1]]
else
- new_cached = build_cached_data(report, options[:grouping], optio…
- new_cached.save!
- result << [reporting_period.date_time, new_cached.value]
+ value = find_value(new_data, reporting_period)
+ if options[:cacheable]
+ new_cached = build_cached_data(report, options[:grouping], opt…
+ new_cached.save! if options[:cacheable]
+ end
+ result << [reporting_period.date_time, value]
end
reporting_period = reporting_period.next
end
@@ -137,6 +142,7 @@ module Saulabs
end
def self.read_cached_data(report, options)
+ return [] if not options[:cacheable]
options[:conditions] ||= []
conditions = [
%w(model_name report_name grouping aggregation conditions).map do …
diff --git a/spec/classes/report_spec.rb b/spec/classes/report_spec.rb
@@ -21,7 +21,7 @@ describe Saulabs::Reportable::Report do
it 'should process the data with the report cache' do
Saulabs::Reportable::ReportCache.should_receive(:process).once.with(
@report,
- { :limit => 100, :grouping => @report.options[:grouping], :conditions …
+ { :limit => 100, :grouping => @report.options[:grouping], :conditions …
)
@report.run
@@ -30,7 +30,7 @@ describe Saulabs::Reportable::Report do
it 'should process the data with the report cache when custom conditions a…
Saulabs::Reportable::ReportCache.should_receive(:process).once.with(
@report,
- { :limit => 100, :grouping => @report.options[:grouping], :conditions …
+ { :limit => 100, :grouping => @report.options[:grouping], :conditions …
)
@report.run(:conditions => { :some => :condition })
@@ -47,7 +47,7 @@ describe Saulabs::Reportable::Report do
Saulabs::Reportable::Grouping.should_receive(:new).once.with(:month).and…
Saulabs::Reportable::ReportCache.should_receive(:process).once.with(
@report,
- { :limit => 100, :grouping => grouping, :conditions => [], :live_data …
+ { :limit => 100, :grouping => grouping, :conditions => [], :live_data …
)
@report.run(:grouping => :month)
You are viewing proxied material from jay.scot. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.