mongoid-report 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +8 -8
- data/Gemfile.lock +1 -1
- data/lib/mongoid/report/scope.rb +14 -0
- data/lib/mongoid/report/version.rb +1 -1
- data/lib/mongoid/report.rb +4 -5
- data/spec/mongoid/report/aggregation_spec.rb +33 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
N2Y0NzI2YzMwYTk3NTljY2VkODkzZjcxYjYyNmM2YzZmYmVlMDdmNw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NWZkNWZlYWMxNzJkYWRkZDkzMWY4MmYxYzZkYmNmMzk5MTIwNWJjZg==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZWZjNjg4NWFlOWFjZWQ0ZmNhODVlYmViYzA1Njg3ZDAwYjhlMDI4YWEwMDM1
|
10
|
+
YTg5NTQ1MDAxNjk5MmI2ZTRhNzkwOTkwNTdmNGU5ZTdkZGRhZTE0OGUwNGQw
|
11
|
+
N2Y4NjMxYjY4ZmYyNTdjZWY1NzYxZGYwMGEyNDc4NjNiNzE1ZDY=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MjcxNzZkZTBhNzEzZDQ1MmNkNDJiMWU1Yjg5NGM0MTA2OWNhMmQ0ZTlhYWEx
|
14
|
+
YjhiNTdhN2ViNDRjYTY1M2E0YjI3Y2EzMTA5OTBiZGU3ZjI2M2IzYTgwZjcw
|
15
|
+
YjIwOWI1ZWM4ZWY2YjA1NDQ2YmMwN2NjMTAyZmMxYWYwMmZmNmM=
|
data/Gemfile.lock
CHANGED
data/lib/mongoid/report/scope.rb
CHANGED
@@ -19,11 +19,25 @@ module Mongoid
|
|
19
19
|
|
20
20
|
def all
|
21
21
|
self.yield unless yielded?
|
22
|
+
queries = compile_queries
|
22
23
|
Collection.new(klass.collection.aggregate(queries), fields)
|
23
24
|
end
|
24
25
|
|
25
26
|
private
|
26
27
|
|
28
|
+
def compile_queries
|
29
|
+
queries.dup.map do |query|
|
30
|
+
query.each do |function_name, values|
|
31
|
+
values.each do |name, value|
|
32
|
+
value = value.call(context) if value.respond_to?(:call)
|
33
|
+
query[function_name][name] = value
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
query
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
27
41
|
def yielded?
|
28
42
|
@yielded
|
29
43
|
end
|
data/lib/mongoid/report.rb
CHANGED
@@ -64,11 +64,10 @@ module Mongoid
|
|
64
64
|
queries = self.settings_property(report_name, :queries)
|
65
65
|
|
66
66
|
options.each do |key, value|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
}])
|
67
|
+
queries
|
68
|
+
.concat([{
|
69
|
+
'$match' => { key => value }
|
70
|
+
}])
|
72
71
|
end
|
73
72
|
end
|
74
73
|
end
|
@@ -264,7 +264,7 @@ describe Mongoid::Report do
|
|
264
264
|
report 'example' do
|
265
265
|
attach_to Model do
|
266
266
|
filter field2: 2,
|
267
|
-
day: -> { Date.parse("20-12-2004").mongoize }
|
267
|
+
day: ->(context) { Date.parse("20-12-2004").mongoize }
|
268
268
|
aggregation_field :field1
|
269
269
|
end
|
270
270
|
end
|
@@ -283,6 +283,38 @@ describe Mongoid::Report do
|
|
283
283
|
expect(rows.size).to eq(1)
|
284
284
|
expect(rows[0]['field1']).to eq(1)
|
285
285
|
end
|
286
|
+
|
287
|
+
class Report18
|
288
|
+
include Mongoid::Report
|
289
|
+
|
290
|
+
def values
|
291
|
+
[1, 2]
|
292
|
+
end
|
293
|
+
|
294
|
+
report 'example' do
|
295
|
+
attach_to Model do
|
296
|
+
group_by :day
|
297
|
+
filter field2: ->(context) { { '$in' => context.values } }
|
298
|
+
aggregation_field :field1
|
299
|
+
end
|
300
|
+
end
|
301
|
+
end
|
302
|
+
|
303
|
+
it 'creates filter in report scope' do
|
304
|
+
klass.create(day: today , field1: 1 , field2: 2)
|
305
|
+
klass.create(day: today , field1: 1 , field2: 2)
|
306
|
+
klass.create(day: yesterday , field1: 1 , field2: 2)
|
307
|
+
klass.create(day: today , field1: 3 , field2: 4)
|
308
|
+
|
309
|
+
example = Report18.new
|
310
|
+
scope = example.aggregate
|
311
|
+
scope = scope.all
|
312
|
+
|
313
|
+
rows = scope['example-models']
|
314
|
+
expect(rows.size).to eq(2)
|
315
|
+
expect(rows[0]['field1']).to eq(1)
|
316
|
+
expect(rows[1]['field1']).to eq(2)
|
317
|
+
end
|
286
318
|
end
|
287
319
|
|
288
320
|
end
|