ResultSet should not be a subclass of array. Just wrap an array instead. #14 - reportable - Fork of reportable required by WarVox, from hdm/reportable.
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
---
(DIR) commit b1a65f43cd95f6d4b7dd56e1deb25214dc21c071
(DIR) parent 61c74a867822300de464ac378c4163a976a912ee
(HTM) Author: Dieter Komendera <dieter@komendera.com>
Date: Wed, 1 Feb 2012 11:19:17 +0100
ResultSet should not be a subclass of array. Just wrap an array instead. #14
This change is needed due to a ruby 1.9.3. inheritance change, see
https://gist.github.com/1415940
Diffstat:
M lib/saulabs/reportable/cumulated_r… | 2 +-
M lib/saulabs/reportable/report_cach… | 2 +-
M lib/saulabs/reportable/report_tag_… | 8 ++++----
M lib/saulabs/reportable/result_set.… | 10 ++++++++--
M spec/classes/report_cache_spec.rb | 2 +-
M spec/classes/report_spec.rb | 8 ++++----
6 files changed, 19 insertions(+), 13 deletions(-)
---
(DIR) diff --git a/lib/saulabs/reportable/cumulated_report.rb b/lib/saulabs/reportable/cumulated_report.rb
@@ -25,7 +25,7 @@ module Saulabs
first_reporting_period = ReportingPeriod.first(options[:grouping], options[:limit], options[:end_date])
acc = initial_cumulative_value(first_reporting_period.date_time, options)
result = []
- data.each do |element|
+ data.to_a.each do |element|
acc += element[1].to_f
result << [element[0], acc]
end
(DIR) diff --git a/lib/saulabs/reportable/report_cache.rb b/lib/saulabs/reportable/report_cache.rb
@@ -64,7 +64,7 @@ module Saulabs
# @option options [DateTime, Boolean] :end_date (false)
# when specified, the report will only include data for the +:limit+ reporting periods until this date.
#
- # @return [Array<Array<DateTime, Float>>]
+ # @return [ResultSet<Array<DateTime, Float>>]
# the result of the report as pairs of {DateTime}s and {Float}s
#
def self.process(report, options, &block)
(DIR) diff --git a/lib/saulabs/reportable/report_tag_helper.rb b/lib/saulabs/reportable/report_tag_helper.rb
@@ -37,7 +37,7 @@ module Saulabs
#
def google_report_tag(data, options = {})
options.reverse_merge!(Config.google_options)
- data = data.collect { |d| d[1] }
+ data = data.to_a.collect { |d| d[1] }
labels = ''
unless options[:labels].empty?
chxr = {}
@@ -93,8 +93,8 @@ module Saulabs
var graph = Raphael('#{options[:dom_id]}');
graph.g.linechart(
-10, 4, #{options[:width]}, #{options[:height]},
- #{(0..data.size).to_a.to_json},
- #{data.map { |d| d[1].send(:eval, options[:format]) }.to_json},
+ #{(0..data.to_a.size).to_a.to_json},
+ #{data.to_a.map { |d| d[1].send(:eval, options[:format]) }.to_json},
#{raphael_options.to_json}
).hover(function() {
this.disc = graph.g.disc(this.x, this.y, 3).attr({fill: "#{options[:hover_fill_color]}", stroke: '#{options[:hover_line_color]}' }).insertBefore(this);
@@ -146,7 +146,7 @@ module Saulabs
%Q{<div id="#{options[:dom_id]}" style="width:#{options[:width]}px;height:#{options[:height]}px;"></div>
<script type="text\/javascript" charset="utf-8">
$(function() {
- var set = #{data.map{|d| d[1] }.to_json},
+ var set = #{data.to_a.map{|d| d[1] }.to_json},
data = [];
for (var i = 0; i < set.length; i++) {
data.push([i, set[i]]);
(DIR) diff --git a/lib/saulabs/reportable/result_set.rb b/lib/saulabs/reportable/result_set.rb
@@ -8,7 +8,7 @@ module Saulabs
# the name of the model and the report the result set
# was generated from.
#
- class ResultSet < ::Array
+ class ResultSet
# the name of the model the result set is based on
#
@@ -18,6 +18,12 @@ module Saulabs
#
attr_reader :report_name
+ # array representation of the result
+ #
+ def to_a
+ @results
+ end
+
# Initializes a new result set.
#
# @param [Array] array
@@ -28,7 +34,7 @@ module Saulabs
# the name of the report the result is based on
#
def initialize(array, model_name, report_name)
- super(array)
+ @results = array
@model_name = model_name
@report_name = report_name.to_s
end
(DIR) diff --git a/spec/classes/report_cache_spec.rb b/spec/classes/report_cache_spec.rb
@@ -368,7 +368,7 @@ describe Saulabs::Reportable::ReportCache do
before do
options = @report.options.merge(:live_data => true)
- @result = Saulabs::Reportable::ReportCache.send(:prepare_result, @new_data, [], @report, options)
+ @result = Saulabs::Reportable::ReportCache.send(:prepare_result, @new_data, [], @report, options).to_a
end
it 'should return an array of length (:limit + 1)' do
(DIR) diff --git a/spec/classes/report_spec.rb b/spec/classes/report_spec.rb
@@ -56,13 +56,13 @@ describe Saulabs::Reportable::Report do
it 'should return an array of the same length as the specified limit when :live_data is false' do
@report = Saulabs::Reportable::Report.new(User, :cumulated_registrations, :limit => 10, :live_data => false)
- @report.run.length.should == 10
+ @report.run.to_a.length.should == 10
end
it 'should return an array of the same length as the specified limit + 1 when :live_data is true' do
@report = Saulabs::Reportable::Report.new(User, :cumulated_registrations, :limit => 10, :live_data => true)
- @report.run.length.should == 11
+ @report.run.to_a.length.should == 11
end
for grouping in [:hour, :day, :week, :month] do
@@ -98,7 +98,7 @@ describe Saulabs::Reportable::Report do
:limit => 10,
:end_date => @end_date
)
- @result = @report.run
+ @result = @report.run.to_a
end
it "should start with the reporting period (end_date - limit.#{grouping.to_s})" do
@@ -127,7 +127,7 @@ describe Saulabs::Reportable::Report do
:limit => 10,
:live_data => live_data
)
- @result = @report.run
+ @result = @report.run.to_a
end
it "should be an array starting reporting period (Time.now - limit.#{grouping.to_s})" do