datagrid 0.5.2 → 0.5.3

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -22,6 +22,7 @@ group :development do
22
22
  gem 'will_paginate', '2.3.15'
23
23
 
24
24
  gem "mongoid", "2.2.2"
25
+ gem "mongo_mapper", ">=0.11.0"
25
26
  gem "bson", "1.4.0"
26
27
  gem "bson_ext", "1.4.0"
27
28
 
@@ -60,12 +60,18 @@ GEM
60
60
  metaclass (~> 0.0.1)
61
61
  mongo (1.4.0)
62
62
  bson (= 1.4.0)
63
+ mongo_mapper (0.11.0)
64
+ activemodel (~> 3.0)
65
+ activesupport (~> 3.0)
66
+ plucky (~> 0.4.0)
63
67
  mongoid (2.2.2)
64
68
  activemodel (~> 3.0)
65
69
  mongo (~> 1.3)
66
70
  tzinfo (~> 0.3.22)
67
71
  multi_json (1.0.4)
68
72
  nokogiri (1.5.0)
73
+ plucky (0.4.3)
74
+ mongo (~> 1.3)
69
75
  polyglot (0.3.3)
70
76
  rack (1.3.5)
71
77
  rack-cache (1.1)
@@ -134,6 +140,7 @@ DEPENDENCIES
134
140
  fastercsv
135
141
  jeweler (~> 1.6.0)
136
142
  mocha
143
+ mongo_mapper (>= 0.11.0)
137
144
  mongoid (= 2.2.2)
138
145
  nokogiri
139
146
  rails (>= 3.0)
@@ -8,20 +8,11 @@ Ruby library that helps you to build and represent table-like data with:
8
8
  * Localization
9
9
  * Export to CSV
10
10
 
11
-
12
- ### Grid DSL
13
-
14
- In order to create a report, you need to define:
15
-
16
- * scope of objects to look through
17
- * filters that will be used to filter data
18
- * columns that should be displayed and sortable (if possible)
19
-
20
-
21
11
  ### ORM Support
22
12
 
23
13
  * ActiveRecord
24
- * Mongoid (beta)
14
+ * Mongoid
15
+ * MongoMapper (beta)
25
16
 
26
17
  [Create an issue](https://github.com/bogdan/datagrid/issues/new) if you want more.
27
18
 
@@ -87,6 +78,15 @@ report.data # => [ header, *rows]
87
78
  report.to_csv # => Yes, it is
88
79
  ```
89
80
 
81
+ ### Grid DSL
82
+
83
+ In order to create a report, you need to define:
84
+
85
+ * scope of objects to look through
86
+ * filters that will be used to filter data
87
+ * columns that should be displayed and sortable (if possible)
88
+
89
+
90
90
  ### Scope
91
91
 
92
92
  Default scope of objects to filter and display.
@@ -185,3 +185,10 @@ If you need a custom interface for your report you should probably build it your
185
185
 
186
186
  [More about frontend](https://github.com/bogdan/datagrid/wiki/Frontend)
187
187
 
188
+ ## Self-Promotion
189
+
190
+ Like datagrid?
191
+
192
+ Follow the repository on [GitHub](https://github.com/bogdan/datagrid/toggle_watch).
193
+
194
+ Read [author blog](http://gusiev.com).
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.2
1
+ 0.5.3
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "datagrid"
8
- s.version = "0.5.2"
8
+ s.version = "0.5.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Bogdan Gusiev"]
12
- s.date = "2012-01-26"
12
+ s.date = "2012-02-13"
13
13
  s.description = "This allows you to easily build datagrid aka data tables with sortable columns and filters"
14
14
  s.email = "agresso@gmail.com"
15
15
  s.extra_rdoc_files = [
@@ -36,6 +36,7 @@ Gem::Specification.new do |s|
36
36
  "lib/datagrid/drivers.rb",
37
37
  "lib/datagrid/drivers/abstract_driver.rb",
38
38
  "lib/datagrid/drivers/active_record.rb",
39
+ "lib/datagrid/drivers/mongo_mapper.rb",
39
40
  "lib/datagrid/drivers/mongoid.rb",
40
41
  "lib/datagrid/engine.rb",
41
42
  "lib/datagrid/filters.rb",
@@ -59,6 +60,7 @@ Gem::Specification.new do |s|
59
60
  "spec/datagrid/active_model_spec.rb",
60
61
  "spec/datagrid/columns_spec.rb",
61
62
  "spec/datagrid/drivers/active_record_spec.rb",
63
+ "spec/datagrid/drivers/mongo_mapper_spec.rb",
62
64
  "spec/datagrid/drivers/mongoid_spec.rb",
63
65
  "spec/datagrid/filters/boolean_enum_filter_spec.rb",
64
66
  "spec/datagrid/filters/composite_filters_spec.rb",
@@ -72,6 +74,7 @@ Gem::Specification.new do |s|
72
74
  "spec/spec_helper.rb",
73
75
  "spec/support/active_record.rb",
74
76
  "spec/support/matchers.rb",
77
+ "spec/support/mongo_mapper.rb",
75
78
  "spec/support/mongoid.rb",
76
79
  "spec/support/simple_report.rb",
77
80
  "spec/support/test_partials/_actions.html.erb"
@@ -98,6 +101,7 @@ Gem::Specification.new do |s|
98
101
  s.add_development_dependency(%q<sqlite3-ruby>, [">= 0"])
99
102
  s.add_development_dependency(%q<will_paginate>, ["= 2.3.15"])
100
103
  s.add_development_dependency(%q<mongoid>, ["= 2.2.2"])
104
+ s.add_development_dependency(%q<mongo_mapper>, [">= 0.11.0"])
101
105
  s.add_development_dependency(%q<bson>, ["= 1.4.0"])
102
106
  s.add_development_dependency(%q<bson_ext>, ["= 1.4.0"])
103
107
  s.add_development_dependency(%q<fastercsv>, [">= 0"])
@@ -114,6 +118,7 @@ Gem::Specification.new do |s|
114
118
  s.add_dependency(%q<sqlite3-ruby>, [">= 0"])
115
119
  s.add_dependency(%q<will_paginate>, ["= 2.3.15"])
116
120
  s.add_dependency(%q<mongoid>, ["= 2.2.2"])
121
+ s.add_dependency(%q<mongo_mapper>, [">= 0.11.0"])
117
122
  s.add_dependency(%q<bson>, ["= 1.4.0"])
118
123
  s.add_dependency(%q<bson_ext>, ["= 1.4.0"])
119
124
  s.add_dependency(%q<fastercsv>, [">= 0"])
@@ -131,6 +136,7 @@ Gem::Specification.new do |s|
131
136
  s.add_dependency(%q<sqlite3-ruby>, [">= 0"])
132
137
  s.add_dependency(%q<will_paginate>, ["= 2.3.15"])
133
138
  s.add_dependency(%q<mongoid>, ["= 2.2.2"])
139
+ s.add_dependency(%q<mongo_mapper>, [">= 0.11.0"])
134
140
  s.add_dependency(%q<bson>, ["= 1.4.0"])
135
141
  s.add_dependency(%q<bson_ext>, ["= 1.4.0"])
136
142
  s.add_dependency(%q<fastercsv>, [">= 0"])
@@ -1,6 +1,7 @@
1
1
  require "datagrid/drivers/abstract_driver"
2
2
  require "datagrid/drivers/active_record"
3
3
  require "datagrid/drivers/mongoid"
4
+ require "datagrid/drivers/mongo_mapper"
4
5
 
5
6
 
6
7
  module Datagrid
@@ -0,0 +1,43 @@
1
+ module Datagrid
2
+ module Drivers
3
+ class MongoMapper < AbstractDriver
4
+
5
+ def self.match?(scope)
6
+ return false unless defined?(::MongoMapper)
7
+ if scope.is_a?(Class)
8
+ scope.ancestors.include?(::MongoMapper::Document)
9
+ else
10
+ scope.is_a?(::Plucky::Query)
11
+ end
12
+ end
13
+
14
+ def to_scope(scope)
15
+ scope.where
16
+ end
17
+
18
+ def where(scope, condition)
19
+ scope.where(condition)
20
+ end
21
+
22
+ def asc(scope, order)
23
+ scope.sort(order.asc)
24
+ end
25
+
26
+ def desc(scope, order)
27
+ scope.sort(order.desc)
28
+ end
29
+
30
+ def default_order(scope, column_name)
31
+ scope.key?(column_name) ? column_name : nil
32
+ end
33
+
34
+ def greater_equal(scope, field, value)
35
+ scope.where(field => {"$gte" => value})
36
+ end
37
+
38
+ def less_equal(scope, field, value)
39
+ scope.where(field => {"$lte" => value})
40
+ end
41
+ end
42
+ end
43
+ end
@@ -28,7 +28,7 @@ module Datagrid
28
28
  end
29
29
 
30
30
  def default_order(scope, column_name)
31
- column_name
31
+ scope.fields.keys.include?(column_name.to_s) ? column_name : nil
32
32
  end
33
33
 
34
34
  def greater_equal(scope, field, value)
@@ -0,0 +1,65 @@
1
+ describe Datagrid::Drivers::MongoMapper do
2
+
3
+ describe ".match?" do
4
+
5
+ subject { described_class }
6
+
7
+ it {should be_match(MongoMapperEntry)}
8
+ # MongoMapper doesn't have a scoped method, instead it has a query method which returns a Plucky::Query object
9
+ it {should be_match(MongoMapperEntry.query)}
10
+ it {should_not be_match(Entry.scoped)}
11
+
12
+ end
13
+ describe "api" do
14
+
15
+ subject do
16
+ MongoMapperGrid.new(
17
+ defined?(_attributes) ? _attributes : {}
18
+ )
19
+ end
20
+
21
+ let!(:first) do
22
+ MongoMapperEntry.create!(
23
+ :group_id => 2,
24
+ :name => "Main First",
25
+ :disabled => false
26
+ )
27
+ end
28
+ let!(:second) do
29
+ MongoMapperEntry.create!(
30
+ :group_id => 3,
31
+ :name => "Main Second",
32
+ :disabled => true
33
+ )
34
+ end
35
+
36
+
37
+ its(:assets) {should include(first, second)}
38
+
39
+ its(:"assets.size") {should == 2}
40
+ its(:rows) {should == [["Main First", 2, false], ["Main Second", 3, true]]}
41
+ its(:header) {should ==[ "Name", "Group", "Disabled"]}
42
+
43
+ its(:data) {should == [[ "Name", "Group", "Disabled"], ["Main First", 2, false], ["Main Second", 3, true]]}
44
+
45
+
46
+ describe "when some filters specified" do
47
+ let(:_attributes) { {:from_group_id => 3} }
48
+ its(:assets) {should_not include(first)}
49
+ its(:assets) {should include(second)}
50
+ end
51
+
52
+ describe "when reverse ordering is specified" do
53
+ let(:_attributes) { {:order => :name, :descending => true} }
54
+ its(:rows) {should == [["Main Second", 3, true], ["Main First", 2, false]]}
55
+ end
56
+ it "should not provide default order for non declared fields" do
57
+ proc {
58
+ test_report(:order => :test) do
59
+ scope { MongoMapperEntry }
60
+ column(:test)
61
+ end
62
+ }.should raise_error(Datagrid::OrderUnsupported)
63
+ end
64
+ end
65
+ end
@@ -52,5 +52,14 @@ describe Datagrid::Drivers::Mongoid do
52
52
  let(:_attributes) { {:order => :name, :descending => true} }
53
53
  its(:rows) {should == [["Main Second", 3, true], ["Main First", 2, false]]}
54
54
  end
55
+
56
+ it "should not provide default order for non declared fields" do
57
+ proc {
58
+ test_report(:order => :test) do
59
+ scope { MongoidEntry }
60
+ column(:test)
61
+ end
62
+ }.should raise_error(Datagrid::OrderUnsupported)
63
+ end
55
64
  end
56
65
  end
@@ -15,6 +15,7 @@ $LOAD_PATH.unshift(File.dirname(__FILE__))
15
15
  require "active_record"
16
16
  require "will_paginate"
17
17
  require "mongoid"
18
+ require "mongo_mapper"
18
19
  require 'datagrid'
19
20
  require "discover"
20
21
  begin
@@ -36,6 +37,7 @@ RSpec.configure do |config|
36
37
  Group.delete_all
37
38
  Entry.delete_all
38
39
  MongoidEntry.delete_all
40
+ MongoMapperEntry.delete_all
39
41
 
40
42
  end
41
43
 
@@ -48,4 +50,5 @@ end
48
50
  # in ./support/ and its subdirectories.
49
51
  Dir["#{File.dirname(__FILE__)}/support/schema.rb"].each {|f| require f}
50
52
  Dir["#{File.dirname(__FILE__)}/support/mongoid.rb"].each {|f| require f}
53
+ Dir["#{File.dirname(__FILE__)}/support/mongo_mapper.rb"].each {|f| require f}
51
54
  Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
@@ -0,0 +1,36 @@
1
+ require "rubygems"
2
+ require 'mongo_mapper'
3
+
4
+ MongoMapper.connection = Mongo::Connection.new('localhost', 27017)
5
+ MongoMapper.database = "datagrid_mongo_mapper"
6
+
7
+ class MongoMapperEntry
8
+ include MongoMapper::Document
9
+
10
+ key :group_id, Integer
11
+ key :name, String
12
+ key :category, String
13
+ key :disabled, Boolean, :default => false
14
+ key :confirmed, Boolean, :default => false
15
+ key :shipping_date, DateTime
16
+ timestamps!
17
+
18
+ end
19
+
20
+ class MongoMapperGrid
21
+ include ::Datagrid
22
+
23
+ scope do
24
+ MongoMapperEntry
25
+ end
26
+
27
+ filter :name
28
+ integer_range_filters(:group_id, {:default => 0}, {:default => 100})
29
+ filter :disabled, :eboolean
30
+
31
+ column :name
32
+ column :group_id
33
+ column :disabled
34
+
35
+ end
36
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: datagrid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.2
4
+ version: 0.5.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-01-26 00:00:00.000000000 Z
12
+ date: 2012-02-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
- requirement: &78305030 !ruby/object:Gem::Requirement
16
+ requirement: &12512220 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '3.0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *78305030
24
+ version_requirements: *12512220
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rake
27
- requirement: &78304740 !ruby/object:Gem::Requirement
27
+ requirement: &12510700 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *78304740
35
+ version_requirements: *12510700
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: bundler
38
- requirement: &78304410 !ruby/object:Gem::Requirement
38
+ requirement: &12509940 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 1.0.0
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *78304410
46
+ version_requirements: *12509940
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: jeweler
49
- requirement: &78304050 !ruby/object:Gem::Requirement
49
+ requirement: &12509440 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 1.6.0
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *78304050
57
+ version_requirements: *12509440
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: ruby-debug
60
- requirement: &78303520 !ruby/object:Gem::Requirement
60
+ requirement: &12508760 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *78303520
68
+ version_requirements: *12508760
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: mocha
71
- requirement: &78302760 !ruby/object:Gem::Requirement
71
+ requirement: &12508120 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *78302760
79
+ version_requirements: *12508120
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: rspec
82
- requirement: &78302520 !ruby/object:Gem::Requirement
82
+ requirement: &12507580 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - =
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: 2.6.0
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *78302520
90
+ version_requirements: *12507580
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: accept_values_for
93
- requirement: &78302120 !ruby/object:Gem::Requirement
93
+ requirement: &12506900 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ! '>='
@@ -98,10 +98,10 @@ dependencies:
98
98
  version: '0'
99
99
  type: :development
100
100
  prerelease: false
101
- version_requirements: *78302120
101
+ version_requirements: *12506900
102
102
  - !ruby/object:Gem::Dependency
103
103
  name: nokogiri
104
- requirement: &78301780 !ruby/object:Gem::Requirement
104
+ requirement: &12522440 !ruby/object:Gem::Requirement
105
105
  none: false
106
106
  requirements:
107
107
  - - ! '>='
@@ -109,10 +109,10 @@ dependencies:
109
109
  version: '0'
110
110
  type: :development
111
111
  prerelease: false
112
- version_requirements: *78301780
112
+ version_requirements: *12522440
113
113
  - !ruby/object:Gem::Dependency
114
114
  name: sqlite3-ruby
115
- requirement: &78301460 !ruby/object:Gem::Requirement
115
+ requirement: &12519640 !ruby/object:Gem::Requirement
116
116
  none: false
117
117
  requirements:
118
118
  - - ! '>='
@@ -120,10 +120,10 @@ dependencies:
120
120
  version: '0'
121
121
  type: :development
122
122
  prerelease: false
123
- version_requirements: *78301460
123
+ version_requirements: *12519640
124
124
  - !ruby/object:Gem::Dependency
125
125
  name: will_paginate
126
- requirement: &78301090 !ruby/object:Gem::Requirement
126
+ requirement: &12518180 !ruby/object:Gem::Requirement
127
127
  none: false
128
128
  requirements:
129
129
  - - =
@@ -131,10 +131,10 @@ dependencies:
131
131
  version: 2.3.15
132
132
  type: :development
133
133
  prerelease: false
134
- version_requirements: *78301090
134
+ version_requirements: *12518180
135
135
  - !ruby/object:Gem::Dependency
136
136
  name: mongoid
137
- requirement: &78300760 !ruby/object:Gem::Requirement
137
+ requirement: &12516820 !ruby/object:Gem::Requirement
138
138
  none: false
139
139
  requirements:
140
140
  - - =
@@ -142,10 +142,21 @@ dependencies:
142
142
  version: 2.2.2
143
143
  type: :development
144
144
  prerelease: false
145
- version_requirements: *78300760
145
+ version_requirements: *12516820
146
+ - !ruby/object:Gem::Dependency
147
+ name: mongo_mapper
148
+ requirement: &12515720 !ruby/object:Gem::Requirement
149
+ none: false
150
+ requirements:
151
+ - - ! '>='
152
+ - !ruby/object:Gem::Version
153
+ version: 0.11.0
154
+ type: :development
155
+ prerelease: false
156
+ version_requirements: *12515720
146
157
  - !ruby/object:Gem::Dependency
147
158
  name: bson
148
- requirement: &78300170 !ruby/object:Gem::Requirement
159
+ requirement: &12531000 !ruby/object:Gem::Requirement
149
160
  none: false
150
161
  requirements:
151
162
  - - =
@@ -153,10 +164,10 @@ dependencies:
153
164
  version: 1.4.0
154
165
  type: :development
155
166
  prerelease: false
156
- version_requirements: *78300170
167
+ version_requirements: *12531000
157
168
  - !ruby/object:Gem::Dependency
158
169
  name: bson_ext
159
- requirement: &78299910 !ruby/object:Gem::Requirement
170
+ requirement: &12530120 !ruby/object:Gem::Requirement
160
171
  none: false
161
172
  requirements:
162
173
  - - =
@@ -164,10 +175,10 @@ dependencies:
164
175
  version: 1.4.0
165
176
  type: :development
166
177
  prerelease: false
167
- version_requirements: *78299910
178
+ version_requirements: *12530120
168
179
  - !ruby/object:Gem::Dependency
169
180
  name: fastercsv
170
- requirement: &78299560 !ruby/object:Gem::Requirement
181
+ requirement: &12526640 !ruby/object:Gem::Requirement
171
182
  none: false
172
183
  requirements:
173
184
  - - ! '>='
@@ -175,7 +186,7 @@ dependencies:
175
186
  version: '0'
176
187
  type: :development
177
188
  prerelease: false
178
- version_requirements: *78299560
189
+ version_requirements: *12526640
179
190
  description: This allows you to easily build datagrid aka data tables with sortable
180
191
  columns and filters
181
192
  email: agresso@gmail.com
@@ -204,6 +215,7 @@ files:
204
215
  - lib/datagrid/drivers.rb
205
216
  - lib/datagrid/drivers/abstract_driver.rb
206
217
  - lib/datagrid/drivers/active_record.rb
218
+ - lib/datagrid/drivers/mongo_mapper.rb
207
219
  - lib/datagrid/drivers/mongoid.rb
208
220
  - lib/datagrid/engine.rb
209
221
  - lib/datagrid/filters.rb
@@ -227,6 +239,7 @@ files:
227
239
  - spec/datagrid/active_model_spec.rb
228
240
  - spec/datagrid/columns_spec.rb
229
241
  - spec/datagrid/drivers/active_record_spec.rb
242
+ - spec/datagrid/drivers/mongo_mapper_spec.rb
230
243
  - spec/datagrid/drivers/mongoid_spec.rb
231
244
  - spec/datagrid/filters/boolean_enum_filter_spec.rb
232
245
  - spec/datagrid/filters/composite_filters_spec.rb
@@ -240,6 +253,7 @@ files:
240
253
  - spec/spec_helper.rb
241
254
  - spec/support/active_record.rb
242
255
  - spec/support/matchers.rb
256
+ - spec/support/mongo_mapper.rb
243
257
  - spec/support/mongoid.rb
244
258
  - spec/support/simple_report.rb
245
259
  - spec/support/test_partials/_actions.html.erb
@@ -258,7 +272,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
258
272
  version: '0'
259
273
  segments:
260
274
  - 0
261
- hash: -972605005
275
+ hash: 1153933139173478709
262
276
  required_rubygems_version: !ruby/object:Gem::Requirement
263
277
  none: false
264
278
  requirements: