Introduction
Introduction Statistics Contact Development Disclaimer Help
ResultSet should not be a subclass of array. Just wrap an array instead. #14 - …
Log
Files
Refs
README
---
commit b1a65f43cd95f6d4b7dd56e1deb25214dc21c071
parent 61c74a867822300de464ac378c4163a976a912ee
Author: Dieter Komendera <[email protected]>
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(-)
---
diff --git a/lib/saulabs/reportable/cumulated_report.rb b/lib/saulabs/reportabl…
@@ -25,7 +25,7 @@ module Saulabs
first_reporting_period = ReportingPeriod.first(options[:grouping], o…
acc = initial_cumulative_value(first_reporting_period.date_time, opt…
result = []
- data.each do |element|
+ data.to_a.each do |element|
acc += element[1].to_f
result << [element[0], acc]
end
diff --git a/lib/saulabs/reportable/report_cache.rb b/lib/saulabs/reportable/re…
@@ -64,7 +64,7 @@ module Saulabs
# @option options [DateTime, Boolean] :end_date (false)
# when specified, the report will only include data for the +:limit+ r…
#
- # @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)
diff --git a/lib/saulabs/reportable/report_tag_helper.rb b/lib/saulabs/reportab…
@@ -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…
@@ -146,7 +146,7 @@ module Saulabs
%Q{<div id="#{options[:dom_id]}" style="width:#{options[:width]}px;hei…
<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]]);
diff --git a/lib/saulabs/reportable/result_set.rb b/lib/saulabs/reportable/resu…
@@ -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
diff --git a/spec/classes/report_cache_spec.rb b/spec/classes/report_cache_spec…
@@ -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_…
+ @result = Saulabs::Reportable::ReportCache.send(:prepare_result, @new_…
end
it 'should return an array of length (:limit + 1)' do
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 …
@report = Saulabs::Reportable::Report.new(User, :cumulated_registrations…
- @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 w…
@report = Saulabs::Reportable::Report.new(User, :cumulated_registrations…
- @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.#{gro…
@@ -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 - lim…
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.