lib/saulabs/reportable/report_cache.rb in reportable-1.0.3 vs lib/saulabs/reportable/report_cache.rb in reportable-1.1.0

- old
+ new

@@ -1,5 +1,8 @@ +require 'saulabs/reportable/reporting_period' +require 'saulabs/reportable/result_set' + module Saulabs module Reportable # The +ReportCache+ class is a regular +ActiveRecord+ model and represents cached results for single {Saulabs::Reportable::ReportingPeriod}s. @@ -7,10 +10,19 @@ # class ReportCache < ActiveRecord::Base set_table_name :reportable_cache + validates_presence_of :model_name + validates_presence_of :report_name + validates_presence_of :grouping + validates_presence_of :aggregation + validates_presence_of :value + validates_presence_of :reporting_period + + attr_accessible :model_name, :report_name, :grouping, :aggregation, :value, :reporting_period, :conditions + self.skip_time_zone_conversion_for_attributes = [:reporting_period] # Clears the cache for the specified +klass+ and +report+ # # @param [Class] klass @@ -82,10 +94,10 @@ reporting_period = reporting_period.next end if options[:live_data] result << [current_reporting_period.date_time, find_value(new_data, current_reporting_period)] end - result + Saulabs::Reportable::ResultSet.new(result, report.klass.name, report.name) end def self.find_value(data, reporting_period) data = data.detect { |d| d[0] == reporting_period } data ? data[1] : 0.0