compendium 1.1.0 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/CHANGELOG.md +9 -3
- data/README.md +15 -2
- data/app/classes/compendium/presenters/chart.rb +1 -1
- data/app/classes/compendium/presenters/option.rb +9 -0
- data/lib/compendium.rb +2 -0
- data/lib/compendium/count_query.rb +17 -0
- data/lib/compendium/dsl.rb +2 -0
- data/lib/compendium/option.rb +1 -1
- data/lib/compendium/param_types.rb +12 -0
- data/lib/compendium/report.rb +9 -7
- data/lib/compendium/version.rb +1 -1
- data/spec/count_query_spec.rb +41 -0
- data/spec/dsl_spec.rb +15 -0
- data/spec/param_types_spec.rb +19 -0
- data/spec/presenters/chart_spec.rb +2 -2
- data/spec/report_spec.rb +2 -2
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZGJkNWVkYjI2YzZhZDYxOWVlODRkYTRhZWEyMGZjZWE5M2JkNTQwMA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ODlmZmY3MWJmYzFkNzJkNWIzYWZkYWNhN2M5NGNkOWFmZGZlYjhkMQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NDE4YmNmMzkwZWY4ZTI4ZTliYjdjYTI5NWI1MmE4ZGM0NTBkYWQ3YzQxZWJi
|
10
|
+
ZjU2NmJhZWQzNmRlNDZjZjM5MWQ4ZjdiODdmMmY4YWEyYTc4ZmU1NmZhOTNh
|
11
|
+
YTkyMDA2OWZkODRjZDExYjhhN2FkOGE1Y2Y5MDM2MmFkODlmN2U=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
YzYwMWVkNzIzNzdhZDA0NDUyMTYyMTZiMjA2YWJmYTU2NzY0OTNjNGUzYWM5
|
14
|
+
ZDU0YTUwNDgxNDgyNTVkMzI2ODFhMzdmMDM5MGQzNDcwNzBmMDgwYzM4OTc0
|
15
|
+
NWVlNzY2N2I3ZGQ1NWViMGEwMzZkNjhlNTFmZTIwOWFhMjViMzM=
|
data/CHANGELOG.md
CHANGED
@@ -1,9 +1,15 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
-
## 1.1.
|
3
|
+
## 1.1.1
|
4
|
+
* Fix crash regressions in Rails 3
|
5
|
+
* 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).
|
7
|
+
* Added `ScalarParam` param type for collecting arbitrary data
|
8
|
+
|
9
|
+
## 1.1.0
|
4
10
|
* Added query filters (allow a result set to be filtered to remove/translate/etc. data)
|
5
11
|
* Extract chart providers into their own gems
|
6
|
-
*
|
12
|
+
* Queries can now be rendered with a remote data source
|
7
13
|
* Added `Report#url` and `Query#url` methods to get the JSON URL
|
8
14
|
|
9
15
|
## 1.0.7
|
@@ -15,4 +21,4 @@
|
|
15
21
|
## 1.0.5
|
16
22
|
* Fixed the `:only` and `:except` options to `Report#run`
|
17
23
|
* Give `ThroughQuery` access to params if the definition block has an arity of 2
|
18
|
-
* Fixed mutating results in a `ThroughQuery` block affecting the parent query
|
24
|
+
* Fixed mutating results in a `ThroughQuery` block affecting the parent query
|
data/README.md
CHANGED
@@ -86,11 +86,24 @@ as JSON. If using the default routes provided by `mount_compendium` (assuming co
|
|
86
86
|
the results of a single query (instead of the entire report) by `POST`ing to
|
87
87
|
<code>report/<i>report_name</i>/<i>query_name</i>.json</code>.
|
88
88
|
|
89
|
+
### Chart Providers
|
90
|
+
|
91
|
+
As of 1.1.0, chart providers have been extracted out of the main repository and are available as their own gems. If you want to render queries as a chart, a chart provider gem is needed.
|
92
|
+
|
93
|
+
If multiple chart providers are installed, you can select the one you wish you use with the following initializer:
|
94
|
+
|
95
|
+
```ruby
|
96
|
+
Compendium.configure do |config|
|
97
|
+
config.chart_provider = :AmCharts # or any other provider name
|
98
|
+
end
|
99
|
+
```
|
100
|
+
|
101
|
+
The following providers are available (If you would like to contribute a chart provider, please let me know and I'll add it to the list):
|
102
|
+
* [compendium-amcharts](https://github.com/dvandersluis/compendium-amcharts) - makes use of [AmCharts.rb](https://github.com/dvandersluis/amcharts.rb)
|
103
|
+
|
89
104
|
### Interaction with other gems
|
90
105
|
* If [accessible_tooltip](https://github.com/dvandersluis/accessible_tooltip) is present, option notes will be rendered
|
91
106
|
in a tooltip rather than as straight text.
|
92
|
-
* [AmCharts.rb](https://github.com/dvandersluis/amcharts.rb) is currently the only chart provider (please create a pull
|
93
|
-
request if you'd like to create another one...)
|
94
107
|
|
95
108
|
## Installation
|
96
109
|
|
@@ -46,6 +46,9 @@ module Compendium::Presenters
|
|
46
46
|
out = ActiveSupport::SafeBuffer.new
|
47
47
|
|
48
48
|
case option.type.to_sym
|
49
|
+
when :scalar
|
50
|
+
out << scalar_field(form)
|
51
|
+
|
49
52
|
when :date
|
50
53
|
out << date_field(form)
|
51
54
|
|
@@ -82,6 +85,12 @@ module Compendium::Presenters
|
|
82
85
|
end
|
83
86
|
end
|
84
87
|
|
88
|
+
def scalar_field(form)
|
89
|
+
content_tag('div', class: 'option-scalar') do
|
90
|
+
form.text_field option.name
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
85
94
|
def dropdown(form, choices = {}, options = {})
|
86
95
|
content_tag('div', class: 'option-dropdown') do
|
87
96
|
form.select option.name, choices, options.symbolize_keys
|
data/lib/compendium.rb
CHANGED
@@ -7,6 +7,7 @@ module Compendium
|
|
7
7
|
autoload :ChartProvider, 'compendium/abstract_chart_provider'
|
8
8
|
autoload :CollectionQuery, 'compendium/collection_query'
|
9
9
|
autoload :ContextWrapper, 'compendium/context_wrapper'
|
10
|
+
autoload :CountQuery, 'compendium/count_query'
|
10
11
|
autoload :DSL, 'compendium/dsl'
|
11
12
|
autoload :Metric, 'compendium/metric'
|
12
13
|
autoload :Option, 'compendium/option'
|
@@ -22,6 +23,7 @@ module Compendium
|
|
22
23
|
autoload :DropdownParam, 'compendium/param_types'
|
23
24
|
autoload :ParamWithChoices, 'compendium/param_types'
|
24
25
|
autoload :RadioParam, 'compendium/param_types'
|
26
|
+
autoload :ScalarParam, 'compendium/param_types'
|
25
27
|
|
26
28
|
def self.reports
|
27
29
|
@reports ||= []
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'compendium/query'
|
2
|
+
|
3
|
+
module Compendium
|
4
|
+
# A CountQuery is a Query which runs an SQL count statement
|
5
|
+
# Often useful in conjunction with a grouped query
|
6
|
+
class CountQuery < Query
|
7
|
+
InvalidCommand = Class.new(StandardError)
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def execute_command(command)
|
12
|
+
return [] if command.nil?
|
13
|
+
raise InvalidCommand unless command.respond_to?(:count)
|
14
|
+
command.count
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/compendium/dsl.rb
CHANGED
data/lib/compendium/option.rb
CHANGED
@@ -7,7 +7,7 @@ module Compendium
|
|
7
7
|
class Option
|
8
8
|
attr_accessor :name, :type, :default, :choices, :options
|
9
9
|
|
10
|
-
delegate :boolean?, :date?, :dropdown?, :radio?, :
|
10
|
+
delegate :boolean?, :date?, :dropdown?, :radio?, :scalar?, to: :type
|
11
11
|
delegate :merge, :merge!, :[], to: :@options
|
12
12
|
|
13
13
|
def initialize(hash = {})
|
@@ -3,6 +3,7 @@ require 'delegate'
|
|
3
3
|
|
4
4
|
module Compendium
|
5
5
|
class Param < ::SimpleDelegator
|
6
|
+
def scalar?; false; end
|
6
7
|
def boolean?; false; end
|
7
8
|
def date?; false; end
|
8
9
|
def dropdown?; false; end
|
@@ -40,6 +41,17 @@ module Compendium
|
|
40
41
|
end
|
41
42
|
end
|
42
43
|
|
44
|
+
class ScalarParam < Param
|
45
|
+
def initialize(obj, *)
|
46
|
+
super obj
|
47
|
+
end
|
48
|
+
|
49
|
+
# A scalar param just keeps track of a value with no modifications
|
50
|
+
def scalar?
|
51
|
+
true
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
43
55
|
class BooleanParam < Param
|
44
56
|
def initialize(obj, *)
|
45
57
|
# If given 0, 1, or a version thereof (ie. "0"), pass it along
|
data/lib/compendium/report.rb
CHANGED
@@ -11,7 +11,7 @@ module Compendium
|
|
11
11
|
extend Compendium::DSL
|
12
12
|
|
13
13
|
delegate :valid?, :errors, to: :params
|
14
|
-
delegate :
|
14
|
+
delegate :report_name, :url, to: 'self.class'
|
15
15
|
|
16
16
|
class << self
|
17
17
|
def inherited(report)
|
@@ -28,8 +28,8 @@ module Compendium
|
|
28
28
|
}
|
29
29
|
end
|
30
30
|
|
31
|
-
def
|
32
|
-
|
31
|
+
def report_name
|
32
|
+
name.underscore.gsub(/_report$/,'').to_sym
|
33
33
|
end
|
34
34
|
|
35
35
|
# Get a URL for this report (format: :json set by default)
|
@@ -59,11 +59,13 @@ module Compendium
|
|
59
59
|
private
|
60
60
|
|
61
61
|
def path_helper(params)
|
62
|
-
unless
|
63
|
-
|
64
|
-
|
62
|
+
raise ActionController::RoutingError, "compendium_reports_run_path must be defined" unless route_helper_defined?
|
63
|
+
Rails.application.routes.url_helpers.compendium_reports_run_path(self.report_name, params.reverse_merge(format: :json))
|
64
|
+
end
|
65
65
|
|
66
|
-
|
66
|
+
def route_helper_defined?
|
67
|
+
@route_helpers ||= Module.new { include Rails.application.routes.url_helpers }
|
68
|
+
@route_helpers.method_defined?(:compendium_reports_run_path)
|
67
69
|
end
|
68
70
|
end
|
69
71
|
|
data/lib/compendium/version.rb
CHANGED
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'compendium/count_query'
|
3
|
+
|
4
|
+
class SingleCounter
|
5
|
+
def count
|
6
|
+
1792
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
class MultipleCounter
|
11
|
+
def count
|
12
|
+
{ 1 => 123, 2 => 456, 3 => 789 }
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe Compendium::CountQuery do
|
17
|
+
subject { described_class.new(:counted_query, { count: true }, -> * { @counter }) }
|
18
|
+
|
19
|
+
describe "#run" do
|
20
|
+
it "should call count on the proc result" do
|
21
|
+
@counter = SingleCounter.new
|
22
|
+
@counter.should_receive(:count).and_return(1234)
|
23
|
+
subject.run(nil, self)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should return the count" do
|
27
|
+
@counter = SingleCounter.new
|
28
|
+
subject.run(nil, self).should == [1792]
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should return a hash if given" do
|
32
|
+
@counter = MultipleCounter.new
|
33
|
+
subject.run(nil, self).should == { 1 => 123, 2 => 456, 3 => 789 }
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should raise an error if the proc does not respond to count" do
|
37
|
+
@counter = Class.new
|
38
|
+
expect { subject.run(nil, self) }.to raise_error Compendium::CountQuery::InvalidCommand
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/spec/dsl_spec.rb
CHANGED
@@ -99,6 +99,21 @@ describe Compendium::DSL do
|
|
99
99
|
its(:collection) { should == query }
|
100
100
|
end
|
101
101
|
end
|
102
|
+
|
103
|
+
context "when given a count option" do
|
104
|
+
subject{ report_class.queries[:counted] }
|
105
|
+
|
106
|
+
context "set to true" do
|
107
|
+
before { report_class.query :counted, count: true }
|
108
|
+
it { should be_a Compendium::CountQuery }
|
109
|
+
end
|
110
|
+
|
111
|
+
context "set to false" do
|
112
|
+
before { report_class.query :counted, count: false }
|
113
|
+
it { should be_a Compendium::Query }
|
114
|
+
it { should_not be_a Compendium::CountQuery }
|
115
|
+
end
|
116
|
+
end
|
102
117
|
end
|
103
118
|
|
104
119
|
describe "#chart" do
|
data/spec/param_types_spec.rb
CHANGED
@@ -3,6 +3,7 @@ require 'compendium/param_types'
|
|
3
3
|
describe Compendium::Param do
|
4
4
|
subject{ described_class.new(:test) }
|
5
5
|
|
6
|
+
it { should_not be_scalar }
|
6
7
|
it { should_not be_boolean }
|
7
8
|
it { should_not be_date }
|
8
9
|
it { should_not be_dropdown }
|
@@ -16,6 +17,20 @@ describe Compendium::Param do
|
|
16
17
|
end
|
17
18
|
end
|
18
19
|
|
20
|
+
describe Compendium::ScalarParam do
|
21
|
+
subject{ described_class.new(123) }
|
22
|
+
|
23
|
+
it { should be_scalar }
|
24
|
+
it { should_not be_boolean }
|
25
|
+
it { should_not be_date }
|
26
|
+
it { should_not be_dropdown }
|
27
|
+
it { should_not be_radio }
|
28
|
+
|
29
|
+
it "should not change values" do
|
30
|
+
subject.should == 123
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
19
34
|
describe Compendium::ParamWithChoices do
|
20
35
|
subject{ described_class.new(0, %w(a b c)) }
|
21
36
|
|
@@ -58,6 +73,7 @@ end
|
|
58
73
|
describe Compendium::BooleanParam do
|
59
74
|
subject{ described_class.new(true) }
|
60
75
|
|
76
|
+
it { should_not be_scalar }
|
61
77
|
it { should be_boolean }
|
62
78
|
it { should_not be_date }
|
63
79
|
it { should_not be_dropdown }
|
@@ -111,6 +127,7 @@ end
|
|
111
127
|
describe Compendium::DateParam do
|
112
128
|
subject{ described_class.new(Date.today) }
|
113
129
|
|
130
|
+
it { should_not be_scalar }
|
114
131
|
it { should_not be_boolean }
|
115
132
|
it { should be_date }
|
116
133
|
it { should_not be_dropdown }
|
@@ -131,6 +148,7 @@ end
|
|
131
148
|
describe Compendium::DropdownParam do
|
132
149
|
subject{ described_class.new(0, %w(a b c)) }
|
133
150
|
|
151
|
+
it { should_not be_scalar }
|
134
152
|
it { should_not be_boolean }
|
135
153
|
it { should_not be_date }
|
136
154
|
it { should be_dropdown }
|
@@ -140,6 +158,7 @@ end
|
|
140
158
|
describe Compendium::RadioParam do
|
141
159
|
subject{ described_class.new(0, %w(a b c)) }
|
142
160
|
|
161
|
+
it { should_not be_scalar }
|
143
162
|
it { should_not be_boolean }
|
144
163
|
it { should_not be_date }
|
145
164
|
it { should_not be_dropdown }
|
@@ -2,7 +2,7 @@ require 'spec_helper'
|
|
2
2
|
require 'compendium/presenters/chart'
|
3
3
|
|
4
4
|
describe Compendium::Presenters::Chart do
|
5
|
-
let(:template) { double('Template',
|
5
|
+
let(:template) { double('Template', protect_against_forgery?: false, request_forgery_protection_token: :authenticity_token, form_authenticity_token: "ABCDEFGHIJ").as_null_object }
|
6
6
|
let(:query) { double('Query', name: 'test_query', results: results, ran?: true, options: {}).as_null_object }
|
7
7
|
let(:results) { Compendium::ResultSet.new([]) }
|
8
8
|
|
@@ -43,7 +43,7 @@ describe Compendium::Presenters::Chart do
|
|
43
43
|
its(:params) { should == { report: { foo: 'bar' } } }
|
44
44
|
|
45
45
|
context "when CSRF protection is enabled" do
|
46
|
-
before { template.stub(
|
46
|
+
before { template.stub(protect_against_forgery?: true) }
|
47
47
|
|
48
48
|
its(:params) { should include authenticity_token: "ABCDEFGHIJ" }
|
49
49
|
end
|
data/spec/report_spec.rb
CHANGED
@@ -28,9 +28,9 @@ describe Compendium::Report do
|
|
28
28
|
its(:metrics) { should_not equal report2.metrics }
|
29
29
|
end
|
30
30
|
|
31
|
-
describe ".
|
31
|
+
describe ".report_name" do
|
32
32
|
subject { TestReport = Class.new(described_class) }
|
33
|
-
its(:
|
33
|
+
its(:report_name) { should == :test }
|
34
34
|
end
|
35
35
|
|
36
36
|
describe "#run" do
|
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.
|
4
|
+
version: 1.1.1
|
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
|
+
date: 2014-04-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
type: :runtime
|
@@ -132,6 +132,7 @@ files:
|
|
132
132
|
- lib/compendium/abstract_chart_provider.rb
|
133
133
|
- lib/compendium/collection_query.rb
|
134
134
|
- lib/compendium/context_wrapper.rb
|
135
|
+
- lib/compendium/count_query.rb
|
135
136
|
- lib/compendium/dsl.rb
|
136
137
|
- lib/compendium/engine.rb
|
137
138
|
- lib/compendium/engine/mount.rb
|
@@ -147,6 +148,7 @@ files:
|
|
147
148
|
- lib/compendium/version.rb
|
148
149
|
- spec/collection_query_spec.rb
|
149
150
|
- spec/context_wrapper_spec.rb
|
151
|
+
- spec/count_query_spec.rb
|
150
152
|
- spec/dsl_spec.rb
|
151
153
|
- spec/metric_spec.rb
|
152
154
|
- spec/option_spec.rb
|
@@ -187,6 +189,7 @@ summary: Ruby on Rails reporting framework
|
|
187
189
|
test_files:
|
188
190
|
- spec/collection_query_spec.rb
|
189
191
|
- spec/context_wrapper_spec.rb
|
192
|
+
- spec/count_query_spec.rb
|
190
193
|
- spec/dsl_spec.rb
|
191
194
|
- spec/metric_spec.rb
|
192
195
|
- spec/option_spec.rb
|