compendium 1.1.2 → 1.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MjZkMmY3MmZhNjk4YzdjMmRkZTBiZDcyZjMwYjUyNjU2MDFmMjM1YQ==
4
+ OGFjMjNjNDU4NzgwOWE0MGQzNmVhNjMyMDRmMzJjZDQwNjNiMzY3Mw==
5
5
  data.tar.gz: !binary |-
6
- N2IxZDJkYzJkNjJkMzYxMGU2OWYwOTQ0NjA2NzdlYmI4ODJjYjQwNw==
6
+ OTNhNjQ5NzIwYjc4NWFmYWJhNmMwN2M3ZjE3Y2M3NTRkMjExNDg0OA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MGVhNDY5ZTViNWJiYzJlMmM4NjY1MGNiNzcxYjNhMzdlODE2ZGYxN2U1ZjI5
10
- YzkwMzg1OTkzMzUyYTc5MjdkYmUyNDFjNmVmNGZjOGFiOWZiZDY1YzNmNGIz
11
- YzQ0MGM1NjA2YTcxMmVlMDUzOWI2ZmU2NGVlNTk1ZTYzOTZiZWU=
9
+ MjZiZDVkYmRiOTRkMjdmMGMxMGY0YTdkZjIzYWM4ZGNlMDYyOTAyMTBmODFj
10
+ ZGY1Y2UwZGM4YmNlNmNiYzk5NWYwMWJkOTNlMTNhYzhjMjFmYWE3MTZhM2E0
11
+ NWQ0ZWY3MDIzMzM4ZTkyMWY5NzQwMzJhZDNhMjUzZjMzNWNjNTM=
12
12
  data.tar.gz: !binary |-
13
- YjQ2MjJmMTViNGU4NDZhYjU2ZDA4OTAwOGMzOGM1MjEyMzQ4NDBlZmJiMTcx
14
- YzU4N2U2NzhmOTMzNDJiODgxYzQxYWQ2NzI0NjA0ZmIzM2U4ODEyMTZlOWZh
15
- NDBkMzRiMGU2YTczNWE2YmQyNDIzMjExZDZlNDdjYzlkYmFjZjQ=
13
+ OTYxODI5ODBiNDIyNDBmZjg4MTAxYWI5YzNmNjJlNjk2ODEwMmY4ZDY0Njdj
14
+ NjIzNWVjMDhhM2EwMTA1ZTdmYzY4YTllZmYxMDgwNjM4NzcyZDZkYTA4NTAw
15
+ N2IxMmMwYmQwNTk1NzIzNGE2ZTM0Y2M0ZjU3NWQzMjUxN2E1NGI=
data/CHANGELOG.md CHANGED
@@ -1,9 +1,13 @@
1
1
  # Change Log
2
2
 
3
+ ## 1.1.2
4
+ * Allow direct access to a chart object without having to render it (useful if the provider allows chart settings to be updated after initialization)
5
+ * Delegate missing methods from ChartProvider classes to the chart
6
+
3
7
  ## 1.1.1
4
8
  * Fix crash regressions in Rails 3
5
9
  * Added `CountQuery` query type which calls count on the result of the given block (for instance a query which is
6
- grouped by day and then counted).
10
+ grouped by day and then counted)
7
11
  * Added `ScalarParam` param type for collecting arbitrary data
8
12
 
9
13
  ## 1.1.0
data/lib/compendium.rb CHANGED
@@ -15,6 +15,7 @@ module Compendium
15
15
  autoload :Query, 'compendium/query'
16
16
  autoload :ResultSet, 'compendium/result_set'
17
17
  autoload :Report, 'compendium/report'
18
+ autoload :SumQuery, 'compendium/sum_query'
18
19
  autoload :ThroughQuery, 'compendium/through_query'
19
20
 
20
21
  autoload :Param, 'compendium/param_types'
@@ -101,6 +101,9 @@ module Compendium
101
101
  params.insert(1, through)
102
102
  elsif opts.fetch(:count, false)
103
103
  query_type = CountQuery
104
+ elsif opts.fetch(:sum, false)
105
+ query_type = SumQuery
106
+ params.insert(1, opts[:sum])
104
107
  end
105
108
 
106
109
  query = query_type.new(*params)
@@ -1,5 +1,6 @@
1
1
  require 'compendium/result_set'
2
2
  require 'compendium/params'
3
+ require 'compendium/metric'
3
4
  require 'compendium/presenters/chart'
4
5
  require 'compendium/presenters/table'
5
6
  require 'collection_of'
@@ -0,0 +1,26 @@
1
+ require 'compendium/query'
2
+
3
+ module Compendium
4
+ # A SumQuery is a Query which runs an SQL sum statement (with a given column)
5
+ # Often useful in conjunction with a grouped query and counter cache
6
+ # (alternately, see CountQuery)
7
+ class SumQuery < Query
8
+ InvalidCommand = Class.new(StandardError)
9
+
10
+ attr_accessor :column
11
+
12
+ def initialize(*args)
13
+ @report = args.shift if arg_is_report?(args.first)
14
+ @column = args.slice!(1)
15
+ super(*args)
16
+ end
17
+
18
+ private
19
+
20
+ def execute_command(command)
21
+ return [] if command.nil?
22
+ raise InvalidCommand unless command.respond_to?(:sum)
23
+ command.sum(column)
24
+ end
25
+ end
26
+ end
@@ -1,3 +1,3 @@
1
1
  module Compendium
2
- VERSION = "1.1.2"
2
+ VERSION = "1.1.3"
3
3
  end
data/spec/dsl_spec.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require 'spec_helper'
1
2
  require 'compendium'
2
3
  require 'compendium/dsl'
3
4
 
@@ -114,6 +115,23 @@ describe Compendium::DSL do
114
115
  it { should_not be_a Compendium::CountQuery }
115
116
  end
116
117
  end
118
+
119
+ context 'when given a sum option' do
120
+ subject{ report_class.queries[:summed] }
121
+
122
+ context 'set to a truthy value' do
123
+ before { report_class.query :summed, sum: :assoc_count }
124
+
125
+ it { should be_a Compendium::SumQuery }
126
+ its(:column) { should == :assoc_count }
127
+ end
128
+
129
+ context 'set to false' do
130
+ before { report_class.query :summed, sum: false }
131
+ it { should be_a Compendium::Query }
132
+ it { should_not be_a Compendium::SumQuery }
133
+ end
134
+ end
117
135
  end
118
136
 
119
137
  describe "#chart" do
@@ -0,0 +1,42 @@
1
+ require 'spec_helper'
2
+ require 'compendium/sum_query'
3
+ require 'compendium/report'
4
+
5
+ class SingleSummer
6
+ def sum(col)
7
+ 1792
8
+ end
9
+ end
10
+
11
+ class MultipleSummer
12
+ def sum(col)
13
+ { 1 => 123, 2 => 456, 3 => 789 }
14
+ end
15
+ end
16
+
17
+ describe Compendium::SumQuery do
18
+ subject { described_class.new(:counted_query, :col, { sum: :col }, -> * { @counter }) }
19
+
20
+ describe "#run" do
21
+ it "should call sum on the proc result" do
22
+ @counter = SingleSummer.new
23
+ @counter.should_receive(:sum).with(:col).and_return(1234)
24
+ subject.run(nil, self)
25
+ end
26
+
27
+ it "should return the sum" do
28
+ @counter = SingleSummer.new
29
+ subject.run(nil, self).should == [1792]
30
+ end
31
+
32
+ it "should return a hash if given" do
33
+ @counter = MultipleSummer.new
34
+ subject.run(nil, self).should == { 1 => 123, 2 => 456, 3 => 789 }
35
+ end
36
+
37
+ it "should raise an error if the proc does not respond to sum" do
38
+ @counter = Class.new
39
+ expect { subject.run(nil, self) }.to raise_error Compendium::SumQuery::InvalidCommand
40
+ end
41
+ end
42
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: compendium
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 1.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Vandersluis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-11 00:00:00.000000000 Z
11
+ date: 2014-09-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  type: :runtime
@@ -144,6 +144,7 @@ files:
144
144
  - lib/compendium/query.rb
145
145
  - lib/compendium/report.rb
146
146
  - lib/compendium/result_set.rb
147
+ - lib/compendium/sum_query.rb
147
148
  - lib/compendium/through_query.rb
148
149
  - lib/compendium/version.rb
149
150
  - spec/collection_query_spec.rb
@@ -161,6 +162,7 @@ files:
161
162
  - spec/report_spec.rb
162
163
  - spec/result_set_spec.rb
163
164
  - spec/spec_helper.rb
165
+ - spec/sum_query_spec.rb
164
166
  - spec/through_query_spec.rb
165
167
  homepage: https://github.com/dvandersluis/compendium
166
168
  licenses:
@@ -202,5 +204,6 @@ test_files:
202
204
  - spec/report_spec.rb
203
205
  - spec/result_set_spec.rb
204
206
  - spec/spec_helper.rb
207
+ - spec/sum_query_spec.rb
205
208
  - spec/through_query_spec.rb
206
209
  has_rdoc: