reportable 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/HISTORY.md CHANGED
@@ -1,3 +1,8 @@
1
+ v1.0.1
2
+ ------
3
+
4
+ * Fixed a bug with PostgreSQL
5
+
1
6
  v1.0.0
2
7
  ------
3
8
 
@@ -6,7 +6,7 @@ class <%= class_name %> < ActiveRecord::Migration
6
6
  t.string :report_name, :null => false
7
7
  t.string :grouping, :null => false
8
8
  t.string :aggregation, :null => false
9
- t.string :condition, :null => false
9
+ t.string :conditions, :null => false
10
10
  t.float :value, :null => false, :default => 0
11
11
  t.datetime :reporting_period, :null => false
12
12
 
@@ -6,8 +6,8 @@ module Saulabs
6
6
  #
7
7
  # @example Cumulated reports as opposed to regular reports
8
8
  #
9
- # [[<DateTime today>, 1], [<DateTime yesterday>, 2], etc.]
10
- # [[<DateTime today>, 3], [<DateTime yesterday>, 2], etc.]
9
+ # [[<DateTime today>, 1], [<DateTime yesterday>, 2], [<DateTime two days ago>, 4], etc.] # result of a regular report
10
+ # [[<DateTime today>, 7], [<DateTime yesterday>, 6], [<DateTime two days ago>, 4], etc.] # result of a cumulated report for the same dataset
11
11
  #
12
12
  class CumulatedReport < Report
13
13
 
@@ -92,13 +92,13 @@ module Saulabs
92
92
  data ? data[1] : 0.0
93
93
  end
94
94
 
95
- def self.build_cached_data(report, grouping, condition, reporting_period, value)
95
+ def self.build_cached_data(report, grouping, conditions, reporting_period, value)
96
96
  self.new(
97
97
  :model_name => report.klass.to_s,
98
98
  :report_name => report.name.to_s,
99
99
  :grouping => grouping.identifier.to_s,
100
100
  :aggregation => report.aggregation.to_s,
101
- :condition => condition.to_s,
101
+ :conditions => conditions.to_s,
102
102
  :reporting_period => reporting_period.date_time,
103
103
  :value => value
104
104
  )
@@ -106,7 +106,9 @@ module Saulabs
106
106
 
107
107
  def self.read_cached_data(report, options)
108
108
  conditions = [
109
- 'model_name = ? AND report_name = ? AND grouping = ? AND aggregation = ? AND `condition` = ?',
109
+ %w(model_name report_name grouping aggregation conditions).map do |column_name|
110
+ "#{self.connection.quote_column_name(column_name)} = ?"
111
+ end.join(' AND '),
110
112
  report.klass.to_s,
111
113
  report.name.to_s,
112
114
  options[:grouping].identifier.to_s,
@@ -122,7 +122,9 @@ describe Saulabs::Reportable::ReportCache do
122
122
  it 'should read existing data from the cache' do
123
123
  Saulabs::Reportable::ReportCache.should_receive(:all).once.with(
124
124
  :conditions => [
125
- 'model_name = ? AND report_name = ? AND grouping = ? AND aggregation = ? AND `condition` = ? AND reporting_period >= ?',
125
+ %w(model_name report_name grouping aggregation conditions).map do |column_name|
126
+ "#{Saulabs::Reportable::ReportCache.connection.quote_column_name(column_name)} = ?"
127
+ end.join(' AND ') + ' AND reporting_period >= ?',
126
128
  @report.klass.to_s,
127
129
  @report.name.to_s,
128
130
  @report.options[:grouping].identifier.to_s,
@@ -141,7 +143,9 @@ describe Saulabs::Reportable::ReportCache do
141
143
  end_date = Time.now
142
144
  Saulabs::Reportable::ReportCache.should_receive(:all).once.with(
143
145
  :conditions => [
144
- 'model_name = ? AND report_name = ? AND grouping = ? AND aggregation = ? AND `condition` = ? AND reporting_period BETWEEN ? AND ?',
146
+ %w(model_name report_name grouping aggregation conditions).map do |column_name|
147
+ "#{Saulabs::Reportable::ReportCache.connection.quote_column_name(column_name)} = ?"
148
+ end.join(' AND ') + ' AND reporting_period BETWEEN ? AND ?',
145
149
  @report.klass.to_s,
146
150
  @report.name.to_s,
147
151
  @report.options[:grouping].identifier.to_s,
@@ -162,7 +166,9 @@ describe Saulabs::Reportable::ReportCache do
162
166
  Saulabs::Reportable::ReportCache.should_receive(:find).once.with(
163
167
  :all,
164
168
  :conditions => [
165
- 'model_name = ? AND report_name = ? AND grouping = ? AND aggregation = ? AND `condition` = ? AND reporting_period >= ?',
169
+ %w(model_name report_name grouping aggregation conditions).map do |column_name|
170
+ "#{Saulabs::Reportable::ReportCache.connection.quote_column_name(column_name)} = ?"
171
+ end.join(' AND ') + ' AND reporting_period >= ?',
166
172
  @report.klass.to_s,
167
173
  @report.name.to_s,
168
174
  grouping.identifier.to_s,
@@ -13,7 +13,7 @@ ActiveRecord::Schema.define(:version => 1) do
13
13
  t.string :report_name, :null => false
14
14
  t.string :grouping, :null => false
15
15
  t.string :aggregation, :null => false
16
- t.string :condition, :null => false
16
+ t.string :conditions, :null => false
17
17
  t.float :value, :null => false, :default => 0
18
18
  t.datetime :reporting_period, :null => false
19
19
 
@@ -24,14 +24,14 @@ ActiveRecord::Schema.define(:version => 1) do
24
24
  :report_name,
25
25
  :grouping,
26
26
  :aggregation,
27
- :condition
27
+ :conditions
28
28
  ], :name => :name_model_grouping_agregation
29
29
  add_index :reportable_cache, [
30
30
  :model_name,
31
31
  :report_name,
32
32
  :grouping,
33
33
  :aggregation,
34
- :condition,
34
+ :conditions,
35
35
  :reporting_period
36
36
  ], :unique => true, :name => :name_model_grouping_aggregation_period
37
37
 
metadata CHANGED
@@ -1,7 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reportable
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ prerelease: false
5
+ segments:
6
+ - 1
7
+ - 0
8
+ - 1
9
+ version: 1.0.1
5
10
  platform: ruby
6
11
  authors:
7
12
  - Marco Otte-Witte
@@ -15,24 +20,32 @@ default_executable:
15
20
  dependencies:
16
21
  - !ruby/object:Gem::Dependency
17
22
  name: activerecord
18
- type: :runtime
19
- version_requirement:
20
- version_requirements: !ruby/object:Gem::Requirement
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
21
25
  requirements:
22
26
  - - ">="
23
27
  - !ruby/object:Gem::Version
28
+ segments:
29
+ - 2
30
+ - 0
31
+ - 0
24
32
  version: 2.0.0
25
- version:
33
+ type: :runtime
34
+ version_requirements: *id001
26
35
  - !ruby/object:Gem::Dependency
27
36
  name: activesupport
28
- type: :runtime
29
- version_requirement:
30
- version_requirements: !ruby/object:Gem::Requirement
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
31
39
  requirements:
32
40
  - - ">="
33
41
  - !ruby/object:Gem::Version
42
+ segments:
43
+ - 2
44
+ - 0
45
+ - 0
34
46
  version: 2.0.0
35
- version:
47
+ type: :runtime
48
+ version_requirements: *id002
36
49
  description: Reportable allows for easy report generation from ActiveRecord and DataMapper models by the addition of the reportable method.
37
50
  email: reportable@saulabs.com
38
51
  executables: []
@@ -81,18 +94,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
81
94
  requirements:
82
95
  - - ">="
83
96
  - !ruby/object:Gem::Version
97
+ segments:
98
+ - 0
84
99
  version: "0"
85
- version:
86
100
  required_rubygems_version: !ruby/object:Gem::Requirement
87
101
  requirements:
88
102
  - - ">="
89
103
  - !ruby/object:Gem::Version
104
+ segments:
105
+ - 0
90
106
  version: "0"
91
- version:
92
107
  requirements: []
93
108
 
94
109
  rubyforge_project:
95
- rubygems_version: 1.3.5
110
+ rubygems_version: 1.3.6
96
111
  signing_key:
97
112
  specification_version: 2
98
113
  summary: Easy report generation for Ruby on Rails