mongoid-report 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/Gemfile.lock +1 -1
- data/lib/mongoid/report.rb +16 -12
- data/lib/mongoid/report/attach_proxy.rb +3 -3
- data/lib/mongoid/report/version.rb +1 -1
- data/spec/mongoid/report_spec.rb +14 -0
- metadata +2 -3
- data/.DS_Store +0 -0
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZjZhMmQ5YzU0ZWUwYzFjMjY2NjUyNjE0ZWFkMWM1ZWUzMzhhNjM2Mg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ODI3YTVkMTNjNjlhYzhhOGNlZTI1NjYwOWE0YjAzYzY0OTQ1ZmViYg==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NzBjM2VhYzBiN2JhMzc4ZjliYWYyNDFjNmE0MDY0ZTNlM2QyYTUxYjZjYmI3
|
10
|
+
YWU0YTA4OTgxMmQyZGZjM2VlZWMyMzhmZDMxZTk1ZTg2OWU3YWFiZWJhMGFi
|
11
|
+
MjA0MTg5MTNlZDUxMmNjZTVlNmYzMjg2NGZjODJkNDc4OTY1MTI=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MjAyOWVkNmNjNGQ2ZjAyMTQyMzYzYzE0ZDVlNzdmZDMzMWE5NjU4NDgyNDli
|
14
|
+
Y2UzYWJkNTQ4NmQzZTMyNWM0MWU3MjMyOGE1ZjM5OGUzYjgwM2E0OGY4MDBm
|
15
|
+
MWQ4OWY2YTg4N2FiYmM3NjljMzQ0NjVjMTc3MDEyYTllMjEwOWM=
|
data/Gemfile.lock
CHANGED
data/lib/mongoid/report.rb
CHANGED
@@ -51,21 +51,21 @@ module Mongoid
|
|
51
51
|
end
|
52
52
|
|
53
53
|
module ClassMethods
|
54
|
-
def attach_to(collection, &block)
|
55
|
-
proxy = AttachProxy.new(self, collection)
|
54
|
+
def attach_to(collection, options = {}, &block)
|
55
|
+
proxy = AttachProxy.new(self, collection, options)
|
56
56
|
proxy.instance_eval(&block)
|
57
57
|
end
|
58
58
|
|
59
59
|
def group_by(*fields)
|
60
|
-
define_report_method(*fields) do |groups,
|
61
|
-
settings[
|
60
|
+
define_report_method(*fields) do |groups, report_name|
|
61
|
+
settings[report_name][:group_by] = groups
|
62
62
|
end
|
63
63
|
end
|
64
64
|
|
65
65
|
def aggregation_field(*fields)
|
66
|
-
define_report_method(*fields) do |columns,
|
66
|
+
define_report_method(*fields) do |columns, report_name|
|
67
67
|
columns.each do |column|
|
68
|
-
add_field(
|
68
|
+
add_field(report_name, column)
|
69
69
|
end
|
70
70
|
end
|
71
71
|
end
|
@@ -86,16 +86,20 @@ module Mongoid
|
|
86
86
|
# We should always specify model to attach fields, groups
|
87
87
|
collection = options.fetch(:for)
|
88
88
|
|
89
|
+
# If user didn't pass as option to name the report we are using
|
90
|
+
# collection class as key for settings.
|
91
|
+
report_name = options.fetch(:as) { collection }
|
92
|
+
|
89
93
|
# We should always have for option
|
90
|
-
initialize_settings_by(
|
94
|
+
initialize_settings_by(report_name)
|
91
95
|
|
92
96
|
# Because of modifying fields(usign exract options method of
|
93
97
|
# ActiveSupport) lets pass fields to the next block with collection.
|
94
|
-
yield fields,
|
98
|
+
yield fields, report_name
|
95
99
|
end
|
96
100
|
|
97
|
-
def initialize_settings_by(
|
98
|
-
settings[
|
101
|
+
def initialize_settings_by(report_name)
|
102
|
+
settings[report_name] ||= settings.fetch(report_name) do
|
99
103
|
{
|
100
104
|
fields: [],
|
101
105
|
group_by: [],
|
@@ -103,8 +107,8 @@ module Mongoid
|
|
103
107
|
end
|
104
108
|
end
|
105
109
|
|
106
|
-
def add_field(
|
107
|
-
settings[
|
110
|
+
def add_field(report_name, field)
|
111
|
+
settings[report_name][:fields] << field
|
108
112
|
|
109
113
|
class_eval <<-FIELD
|
110
114
|
def #{field}
|
@@ -1,13 +1,13 @@
|
|
1
1
|
module Mongoid
|
2
2
|
module Report
|
3
3
|
|
4
|
-
AttachProxy = Struct.new(:context, :collection) do
|
4
|
+
AttachProxy = Struct.new(:context, :collection, :options) do
|
5
5
|
def aggregation_field(*fields)
|
6
|
-
context.aggregation_field(*fields, for: collection)
|
6
|
+
context.aggregation_field(*fields, options.merge(for: collection))
|
7
7
|
end
|
8
8
|
|
9
9
|
def group_by(*fields)
|
10
|
-
context.group_by(*fields, for: collection)
|
10
|
+
context.group_by(*fields, options.merge(for: collection))
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
data/spec/mongoid/report_spec.rb
CHANGED
@@ -55,4 +55,18 @@ describe Mongoid::Report do
|
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
58
|
+
class Report6
|
59
|
+
include Mongoid::Report
|
60
|
+
|
61
|
+
attach_to Model, as: 'example1' do
|
62
|
+
aggregation_field :field1
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe '.as' do
|
67
|
+
it 'creates settings with "as" name' do
|
68
|
+
expect(Report6.settings).to have_key('example1')
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
58
72
|
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.
|
4
|
+
version: 0.0.6
|
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-
|
11
|
+
date: 2014-06-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mongoid
|
@@ -59,7 +59,6 @@ executables: []
|
|
59
59
|
extensions: []
|
60
60
|
extra_rdoc_files: []
|
61
61
|
files:
|
62
|
-
- .DS_Store
|
63
62
|
- .gitignore
|
64
63
|
- .rspec
|
65
64
|
- .ruby-version
|
data/.DS_Store
DELETED
Binary file
|