mongoid-report 0.1.0 → 0.1.1

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
- Y2Y4YTU4MzMzZmQ0MmRmYzNhYTMwZWM5MDViNDFhOTExMDJlYWMxNg==
4
+ N2Y0NzI2YzMwYTk3NTljY2VkODkzZjcxYjYyNmM2YzZmYmVlMDdmNw==
5
5
  data.tar.gz: !binary |-
6
- YzNkMDcxYjU1NjQ2ZGI5MjAwYzk2OGFlYWYzOGNmOTQyYjMzMjFiMg==
6
+ NWZkNWZlYWMxNzJkYWRkZDkzMWY4MmYxYzZkYmNmMzk5MTIwNWJjZg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- YjY5OTdjZGY5ODQ4MDRmMGZlMTVlMzUwMjM4NWQzOGMwZDAzODE3OWNiNGRk
10
- MzBkMDMwOTZiMTgyZmYxZmZjZjliMmEwOTZjNTY1YjYyYzBhODk4YjE2ZGRh
11
- NjZlYTAyNDRiNjA1NzE0MzY3MmUwZGQ5YTE0NTY0M2YxMTU5NzQ=
9
+ ZWZjNjg4NWFlOWFjZWQ0ZmNhODVlYmViYzA1Njg3ZDAwYjhlMDI4YWEwMDM1
10
+ YTg5NTQ1MDAxNjk5MmI2ZTRhNzkwOTkwNTdmNGU5ZTdkZGRhZTE0OGUwNGQw
11
+ N2Y4NjMxYjY4ZmYyNTdjZWY1NzYxZGYwMGEyNDc4NjNiNzE1ZDY=
12
12
  data.tar.gz: !binary |-
13
- M2FlNTYzNzJmOTZmNmY2ZTNmNDc3MTA3ODg2NzliNjNjMTFjZDA5MDVmZThj
14
- YTAyZDY2ZTUyNWIzOGFjMGY5M2JiMjEzNTQ4ZTIwZmY1ZTUxZDY4NzA1NzAz
15
- MDRlYjJlZTQ3ODViMTc1MGI1YzBhYWZhMjQ3YTU3YzBhYjQxNmE=
13
+ MjcxNzZkZTBhNzEzZDQ1MmNkNDJiMWU1Yjg5NGM0MTA2OWNhMmQ0ZTlhYWEx
14
+ YjhiNTdhN2ViNDRjYTY1M2E0YjI3Y2EzMTA5OTBiZGU3ZjI2M2IzYTgwZjcw
15
+ YjIwOWI1ZWM4ZWY2YjA1NDQ2YmMwN2NjMTAyZmMxYWYwMmZmNmM=
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mongoid-report (0.1.0)
4
+ mongoid-report (0.1.1)
5
5
  mongoid (> 3.0.1)
6
6
 
7
7
  GEM
@@ -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
@@ -1,5 +1,5 @@
1
1
  module Mongoid
2
2
  module Report
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.1"
4
4
  end
5
5
  end
@@ -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
- value = value.call if value.respond_to?(:call)
68
- queries
69
- .concat([{
70
- '$match' => { key => value }
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid-report
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexandr Korsak