mongoid-report 0.0.9 → 0.0.10

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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- Mzk5ZjE1YTRjNTNkZjRmOWVlMzM1OTJjMjExZWQ3NjljOTk5NTY5Mw==
4
+ MGI5NjU2YTI3ZTI0MmIxYzA0ZTRiYTQ4ZDhiZGNmY2FiZDRhMmViMg==
5
5
  data.tar.gz: !binary |-
6
- ZmU3YWU2NDBiN2I4NDZlMjViZGM0MTljNGY2NGIxYmNkZWExN2ViNA==
6
+ MDY0ODA4ZGM4MWI0NzViOTljMTQ2ZTYwNjNjYWU3NTlkY2Q3MDMxMg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- YmY2NTA3ZGZjNjY4ZTU3NmNiZGQ1MGIzM2U4YWNhM2FkMWQ5YTA4NWZhMzll
10
- N2JjM2VmNmNjYmFhMjEyYTI4ZGY4MDRkNTk2YzQ3NTI0Y2IxNDk4MTUyODY4
11
- OTY2ZjAzNGMxZjkwOWRmNmIzYjA3MGY3ZTE3MjY2MTg3OWJiZWY=
9
+ ZmI4YWEzNzIwMDM0MTdjODBmZDFlNjAyYTliMTliZmVmYTA1NDcwMWJhY2Jj
10
+ N2IzYzY4M2UzYzNkNWQ2OTYwY2FlYWE2NGY4ZTQ3YmU0NjQyMGY0Njc4NTdk
11
+ ZTJkZjQ5MTQ4YTc3NTViMzVhMTQ4MjU4NGRmYTY3Y2U4ZjgyMWQ=
12
12
  data.tar.gz: !binary |-
13
- YzM2ZTZmZWFlODA4NjI1MTIzYTY0NDk5YzkyM2EwNDQ3ZWYwNmQ0MTY4ZGI2
14
- NjUxZjQzZDg5ZmU3NDU3ZWU4OWIxMWZjZGU5YmRjMmJhMTgyYzNiNTJjNjBj
15
- NDQ5YWZjNGNkOTU1MDBlMTEyNjE2N2U4ODIzNDJjYmQ0YjJiZTA=
13
+ NzUxMGQzNzNjZjU5Yzk0ZWViNWFlNWU0MTI2YWUwOGE3MDk5YzM4ZjZjZjEw
14
+ YjU2ODU0ZTRlN2MzNWY3MTYzNDE4YTg1ZjdjZjM2ZGQ3MGE3NDQ2NzY4ZWZh
15
+ YTRmNTExYmMwNTk2ZjhmMjFkNGFkMmQwZDBjOTI4Mzk0NGQ2NGQ=
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mongoid-report (0.0.9)
4
+ mongoid-report (0.0.10)
5
5
  mongoid (> 3.0.1)
6
6
 
7
7
  GEM
@@ -0,0 +1,15 @@
1
+ module Mongoid
2
+ module Report
3
+
4
+ ReportProxy = Struct.new(:context, :name) do
5
+ def attach_to(model, options = {}, &block)
6
+ as = options.fetch(:as) { model.collection.name }
7
+
8
+ options.merge!(as: "#{name}-#{as}") if as
9
+
10
+ context.attach_to(model, options, &block)
11
+ end
12
+ end
13
+
14
+ end
15
+ end
@@ -1,5 +1,5 @@
1
1
  module Mongoid
2
2
  module Report
3
- VERSION = "0.0.9"
3
+ VERSION = "0.0.10"
4
4
  end
5
5
  end
@@ -6,6 +6,7 @@ require_relative 'report/attach_proxy'
6
6
  require_relative 'report/collection'
7
7
  require_relative 'report/scope'
8
8
  require_relative 'report/scope_collection'
9
+ require_relative 'report/report_proxy'
9
10
 
10
11
  module Mongoid
11
12
  module Report
@@ -67,6 +68,11 @@ module Mongoid
67
68
  end
68
69
  end
69
70
 
71
+ def report(name, &block)
72
+ proxy = ReportProxy.new(self, name)
73
+ proxy.instance_eval(&block)
74
+ end
75
+
70
76
  def fields(collection)
71
77
  settings_property(collection, :fields)
72
78
  end
@@ -121,6 +121,51 @@ describe Mongoid::Report do
121
121
  expect(rows[1]['field2']).to eq(2)
122
122
  expect(rows[1]['day']).to eq(yesterday)
123
123
  end
124
+
125
+ class Report8
126
+ include Mongoid::Report
127
+
128
+ report 'example' do
129
+ attach_to Model, as: 'model1' do
130
+ group_by :day
131
+ aggregation_field :field1
132
+ end
133
+
134
+ attach_to Model, as: 'model2' do
135
+ group_by :day
136
+ aggregation_field :field2
137
+ end
138
+ end
139
+ end
140
+
141
+ it 'should still aggregate with combined report' do
142
+ klass.create(day: today , field1: 1 , field2: 2)
143
+ klass.create(day: today , field1: 1 , field2: 2)
144
+ klass.create(day: yesterday , field1: 1 , field2: 2)
145
+ klass.create(day: two_days_ago , field1: 1 , field2: 2)
146
+
147
+ example = Report8.new
148
+ scope = example.aggregate
149
+ scope
150
+ .query('$match' => { :day => { '$gte' => yesterday.mongoize, '$lte' => today.mongoize } })
151
+ .yield
152
+ .query('$sort' => { day: -1 })
153
+ scope = scope.all
154
+
155
+ rows = scope['example-model1']
156
+ expect(rows.size).to eq(2)
157
+ expect(rows[0]['field1']).to eq(2)
158
+ expect(rows[0]['day']).to eq(today)
159
+ expect(rows[1]['field1']).to eq(1)
160
+ expect(rows[1]['day']).to eq(yesterday)
161
+
162
+ rows = scope['example-model2']
163
+ expect(rows.size).to eq(2)
164
+ expect(rows[0]['field2']).to eq(4)
165
+ expect(rows[0]['day']).to eq(today)
166
+ expect(rows[1]['field2']).to eq(2)
167
+ expect(rows[1]['day']).to eq(yesterday)
168
+ end
124
169
  end
125
170
 
126
171
  end
@@ -68,4 +68,25 @@ describe Mongoid::Report do
68
68
  expect(Report6.settings).to have_key('example1')
69
69
  end
70
70
  end
71
+
72
+ class Report7
73
+ include Mongoid::Report
74
+
75
+ report 'example' do
76
+ attach_to Model, as: 'model1' do
77
+ aggregation_field :field1
78
+ end
79
+
80
+ attach_to Model do
81
+ aggregation_field :field1
82
+ end
83
+ end
84
+ end
85
+
86
+ describe '.report' do
87
+ it 'creates settings with report-<attached-model-name' do
88
+ expect(Report7.settings).to have_key('example-model1')
89
+ expect(Report7.settings).to have_key("example-#{Model.collection.name}")
90
+ end
91
+ end
71
92
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid-report
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexandr Korsak
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-12 00:00:00.000000000 Z
11
+ date: 2014-06-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mongoid
@@ -73,6 +73,7 @@ files:
73
73
  - lib/mongoid/report/attach_proxy.rb
74
74
  - lib/mongoid/report/collection.rb
75
75
  - lib/mongoid/report/queries_builder.rb
76
+ - lib/mongoid/report/report_proxy.rb
76
77
  - lib/mongoid/report/scope.rb
77
78
  - lib/mongoid/report/scope_collection.rb
78
79
  - lib/mongoid/report/version.rb