datagrid 0.5.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.0
1
+ 0.5.1
data/datagrid.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "datagrid"
8
- s.version = "0.5.0"
8
+ s.version = "0.5.1"
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-03"
12
+ s.date = "2012-01-26"
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 = [
@@ -79,7 +79,7 @@ Gem::Specification.new do |s|
79
79
  s.homepage = "http://github.com/bogdan/datagrid"
80
80
  s.licenses = ["MIT"]
81
81
  s.require_paths = ["lib"]
82
- s.rubygems_version = "1.8.11"
82
+ s.rubygems_version = "1.8.10"
83
83
  s.summary = "Ruby gem to create datagrids"
84
84
 
85
85
  if s.respond_to? :specification_version then
@@ -1,8 +1,7 @@
1
1
  require "datagrid/utils"
2
2
 
3
3
  module Datagrid
4
-
5
-
4
+
6
5
  module Columns
7
6
  require "datagrid/columns/column"
8
7
 
@@ -17,7 +17,37 @@ module Datagrid
17
17
  end
18
18
 
19
19
 
20
- #TODO api declaration
20
+ def self.match?(scope)
21
+ raise NotImplementedError
22
+ end
23
+
24
+ def to_scope(scope)
25
+ raise NotImplementedError
26
+ end
27
+
28
+ def where(scope, condition)
29
+ raise NotImplementedError
30
+ end
31
+
32
+ def asc(scope, order)
33
+ raise NotImplementedError
34
+ end
35
+
36
+ def desc(scope, order)
37
+ raise NotImplementedError
38
+ end
39
+
40
+ def default_order(scope, column_name)
41
+ raise NotImplementedError
42
+ end
43
+
44
+ def greater_equal(scope, field, value)
45
+ raise NotImplementedError
46
+ end
47
+
48
+ def less_equal(scope, field, value)
49
+ raise NotImplementedError
50
+ end
21
51
 
22
52
  end
23
53
  end
@@ -29,13 +29,17 @@ module Datagrid
29
29
  scope.reorder(order).reverse_order
30
30
  end
31
31
 
32
- def table_name(scope)
33
- scope.table_name
34
- end
35
-
36
32
  def default_order(scope, column_name)
37
33
  scope.column_names.include?(column_name.to_s) ? [scope.table_name, column_name].join(".") : nil
38
34
  end
35
+
36
+ def greater_equal(scope, field, value)
37
+ scope.where(["#{field} >= ?", value])
38
+ end
39
+
40
+ def less_equal(scope, field, value)
41
+ scope.where(["#{field} <= ?", value])
42
+ end
39
43
  end
40
44
  end
41
45
  end
@@ -31,6 +31,13 @@ module Datagrid
31
31
  column_name
32
32
  end
33
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
34
41
  end
35
42
  end
36
43
  end
@@ -11,29 +11,41 @@ module Datagrid
11
11
  end # self.included
12
12
 
13
13
  module ClassMethods
14
- #TODO: decide what to do with cross-orm
15
14
 
16
- def date_range_filters(field, from_name = :"from_#{field}", to_name = :"to_#{field}")
17
- filter(from_name, :date) do |date|
18
- self.scoped(:conditions => ["#{field} >= ?", date])
15
+ def date_range_filters(field, from_options = {}, to_options = {})
16
+ from_options = normalize_composite_filter_options(from_options, field)
17
+ to_options = normalize_composite_filter_options(to_options, field)
18
+
19
+ filter(from_options[:name] || :"from_#{field}", :date) do |date|
20
+ driver.greater_equal(self, field, date)
19
21
  end
20
- filter(to_name, :date) do |date|
21
- self.scoped(:conditions => ["#{field} <= ?", date])
22
+ filter(to_options[:name] || :"to_#{field}", :date) do |date|
23
+ driver.less_equal(self, field, date)
22
24
  end
23
25
  end
24
26
 
25
- def integer_range_filters(field, from_name = :"from_#{field}", to_name = :"to_#{field}")
26
- filter(from_name, :integer) do |value|
27
- self.scoped(:conditions => "#{field} >= #{value}")
27
+ def integer_range_filters(field, from_options = {}, to_options = {})
28
+ from_options = normalize_composite_filter_options(from_options, field)
29
+ to_options = normalize_composite_filter_options(to_options, field)
30
+ filter(from_options[:name] || :"from_#{field}", :integer) do |value|
31
+ driver.greater_equal(self, field, value)
28
32
  end
29
- filter(to_name, :integer) do |value|
30
- self.scoped(:conditions => "#{field} <= #{value}")
33
+ filter(to_options[:name] || :"to_#{field}", :integer) do |value|
34
+ driver.less_equal(self, field, value)
31
35
  end
32
36
  end
37
+
38
+ def normalize_composite_filter_options(options, field)
39
+ if options.is_a?(String) || options.is_a?(Symbol)
40
+ options = {:name => options}
41
+ end
42
+ options
43
+ end
33
44
  end # ClassMethods
34
45
 
35
46
  module InstanceMethods
36
47
 
48
+
37
49
  end # InstanceMethods
38
50
 
39
51
  end
@@ -2,7 +2,7 @@
2
2
  # We can not call instance_eval on ActiveRecord::Relation class
3
3
  # because it will automatically convert it to an array because #instance_eval
4
4
  # is not included in the method list that do not cause force result loading
5
- # That is why we need thi helper class
5
+ # That is why we need this helper class
6
6
  class Datagrid::Filters::FilterEval
7
7
 
8
8
  attr_accessor :filter, :scope, :value
@@ -17,6 +17,10 @@ class Datagrid::Filters::FilterEval
17
17
  instance_exec @value, &(@filter.block)
18
18
  end
19
19
 
20
+ def driver
21
+ @filter.grid.driver
22
+ end
23
+
20
24
  def method_missing(meth, *args, &blk)
21
25
  if @scope.respond_to?(meth)
22
26
  @scope.send(meth, *args, &blk)
@@ -43,9 +43,9 @@ describe Datagrid::Drivers::Mongoid do
43
43
 
44
44
 
45
45
  describe "when some filters specified" do
46
- let(:_attributes) { {:group_id => 2} }
47
- its(:assets) {should include(first)}
48
- its(:assets) {should_not include(second)}
46
+ let(:_attributes) { {:from_group_id => 3} }
47
+ its(:assets) {should_not include(first)}
48
+ its(:assets) {should include(second)}
49
49
  end
50
50
 
51
51
  describe "when reverse ordering is specified" do
@@ -34,9 +34,7 @@ class MongoidGrid
34
34
  end
35
35
 
36
36
  filter :name
37
- filter :group_id do |value|
38
- where(:group_id => value)
39
- end
37
+ integer_range_filters(:group_id, {:default => 0}, {:default => 100})
40
38
  filter :disabled, :eboolean
41
39
 
42
40
  column :name
metadata CHANGED
@@ -1,256 +1,189 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: datagrid
3
- version: !ruby/object:Gem::Version
4
- hash: 11
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.1
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 5
9
- - 0
10
- version: 0.5.0
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Bogdan Gusiev
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2012-01-03 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
21
- type: :runtime
22
- requirement: &id001 !ruby/object:Gem::Requirement
23
- none: false
24
- requirements:
25
- - - ">="
26
- - !ruby/object:Gem::Version
27
- hash: 7
28
- segments:
29
- - 3
30
- - 0
31
- version: "3.0"
32
- prerelease: false
12
+ date: 2012-01-26 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
33
15
  name: rails
34
- version_requirements: *id001
35
- - !ruby/object:Gem::Dependency
36
- type: :development
37
- requirement: &id002 !ruby/object:Gem::Requirement
16
+ requirement: &75484050 !ruby/object:Gem::Requirement
38
17
  none: false
39
- requirements:
40
- - - ">="
41
- - !ruby/object:Gem::Version
42
- hash: 3
43
- segments:
44
- - 0
45
- version: "0"
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '3.0'
22
+ type: :runtime
46
23
  prerelease: false
24
+ version_requirements: *75484050
25
+ - !ruby/object:Gem::Dependency
47
26
  name: rake
48
- version_requirements: *id002
49
- - !ruby/object:Gem::Dependency
27
+ requirement: &75483760 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
50
33
  type: :development
51
- requirement: &id003 !ruby/object:Gem::Requirement
34
+ prerelease: false
35
+ version_requirements: *75483760
36
+ - !ruby/object:Gem::Dependency
37
+ name: bundler
38
+ requirement: &75483430 !ruby/object:Gem::Requirement
52
39
  none: false
53
- requirements:
40
+ requirements:
54
41
  - - ~>
55
- - !ruby/object:Gem::Version
56
- hash: 23
57
- segments:
58
- - 1
59
- - 0
60
- - 0
42
+ - !ruby/object:Gem::Version
61
43
  version: 1.0.0
62
- prerelease: false
63
- name: bundler
64
- version_requirements: *id003
65
- - !ruby/object:Gem::Dependency
66
44
  type: :development
67
- requirement: &id004 !ruby/object:Gem::Requirement
45
+ prerelease: false
46
+ version_requirements: *75483430
47
+ - !ruby/object:Gem::Dependency
48
+ name: jeweler
49
+ requirement: &75483070 !ruby/object:Gem::Requirement
68
50
  none: false
69
- requirements:
51
+ requirements:
70
52
  - - ~>
71
- - !ruby/object:Gem::Version
72
- hash: 15
73
- segments:
74
- - 1
75
- - 6
76
- - 0
53
+ - !ruby/object:Gem::Version
77
54
  version: 1.6.0
78
- prerelease: false
79
- name: jeweler
80
- version_requirements: *id004
81
- - !ruby/object:Gem::Dependency
82
55
  type: :development
83
- requirement: &id005 !ruby/object:Gem::Requirement
84
- none: false
85
- requirements:
86
- - - ">="
87
- - !ruby/object:Gem::Version
88
- hash: 3
89
- segments:
90
- - 0
91
- version: "0"
92
56
  prerelease: false
57
+ version_requirements: *75483070
58
+ - !ruby/object:Gem::Dependency
93
59
  name: ruby-debug
94
- version_requirements: *id005
95
- - !ruby/object:Gem::Dependency
96
- type: :development
97
- requirement: &id006 !ruby/object:Gem::Requirement
60
+ requirement: &75482550 !ruby/object:Gem::Requirement
98
61
  none: false
99
- requirements:
100
- - - ">="
101
- - !ruby/object:Gem::Version
102
- hash: 3
103
- segments:
104
- - 0
105
- version: "0"
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :development
106
67
  prerelease: false
68
+ version_requirements: *75482550
69
+ - !ruby/object:Gem::Dependency
107
70
  name: mocha
108
- version_requirements: *id006
109
- - !ruby/object:Gem::Dependency
110
- type: :development
111
- requirement: &id007 !ruby/object:Gem::Requirement
71
+ requirement: &75481780 !ruby/object:Gem::Requirement
112
72
  none: false
113
- requirements:
114
- - - "="
115
- - !ruby/object:Gem::Version
116
- hash: 23
117
- segments:
118
- - 2
119
- - 6
120
- - 0
121
- version: 2.6.0
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
122
78
  prerelease: false
79
+ version_requirements: *75481780
80
+ - !ruby/object:Gem::Dependency
123
81
  name: rspec
124
- version_requirements: *id007
125
- - !ruby/object:Gem::Dependency
126
- type: :development
127
- requirement: &id008 !ruby/object:Gem::Requirement
82
+ requirement: &75481530 !ruby/object:Gem::Requirement
128
83
  none: false
129
- requirements:
130
- - - ">="
131
- - !ruby/object:Gem::Version
132
- hash: 3
133
- segments:
134
- - 0
135
- version: "0"
84
+ requirements:
85
+ - - =
86
+ - !ruby/object:Gem::Version
87
+ version: 2.6.0
88
+ type: :development
136
89
  prerelease: false
90
+ version_requirements: *75481530
91
+ - !ruby/object:Gem::Dependency
137
92
  name: accept_values_for
138
- version_requirements: *id008
139
- - !ruby/object:Gem::Dependency
140
- type: :development
141
- requirement: &id009 !ruby/object:Gem::Requirement
93
+ requirement: &75481140 !ruby/object:Gem::Requirement
142
94
  none: false
143
- requirements:
144
- - - ">="
145
- - !ruby/object:Gem::Version
146
- hash: 3
147
- segments:
148
- - 0
149
- version: "0"
95
+ requirements:
96
+ - - ! '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ type: :development
150
100
  prerelease: false
101
+ version_requirements: *75481140
102
+ - !ruby/object:Gem::Dependency
151
103
  name: nokogiri
152
- version_requirements: *id009
153
- - !ruby/object:Gem::Dependency
154
- type: :development
155
- requirement: &id010 !ruby/object:Gem::Requirement
104
+ requirement: &75480800 !ruby/object:Gem::Requirement
156
105
  none: false
157
- requirements:
158
- - - ">="
159
- - !ruby/object:Gem::Version
160
- hash: 3
161
- segments:
162
- - 0
163
- version: "0"
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ type: :development
164
111
  prerelease: false
112
+ version_requirements: *75480800
113
+ - !ruby/object:Gem::Dependency
165
114
  name: sqlite3-ruby
166
- version_requirements: *id010
167
- - !ruby/object:Gem::Dependency
168
- type: :development
169
- requirement: &id011 !ruby/object:Gem::Requirement
115
+ requirement: &75480480 !ruby/object:Gem::Requirement
170
116
  none: false
171
- requirements:
172
- - - "="
173
- - !ruby/object:Gem::Version
174
- hash: 29
175
- segments:
176
- - 2
177
- - 3
178
- - 15
179
- version: 2.3.15
117
+ requirements:
118
+ - - ! '>='
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ type: :development
180
122
  prerelease: false
123
+ version_requirements: *75480480
124
+ - !ruby/object:Gem::Dependency
181
125
  name: will_paginate
182
- version_requirements: *id011
183
- - !ruby/object:Gem::Dependency
184
- type: :development
185
- requirement: &id012 !ruby/object:Gem::Requirement
126
+ requirement: &75480110 !ruby/object:Gem::Requirement
186
127
  none: false
187
- requirements:
188
- - - "="
189
- - !ruby/object:Gem::Version
190
- hash: 3
191
- segments:
192
- - 2
193
- - 2
194
- - 2
195
- version: 2.2.2
128
+ requirements:
129
+ - - =
130
+ - !ruby/object:Gem::Version
131
+ version: 2.3.15
132
+ type: :development
196
133
  prerelease: false
134
+ version_requirements: *75480110
135
+ - !ruby/object:Gem::Dependency
197
136
  name: mongoid
198
- version_requirements: *id012
199
- - !ruby/object:Gem::Dependency
200
- type: :development
201
- requirement: &id013 !ruby/object:Gem::Requirement
137
+ requirement: &75479780 !ruby/object:Gem::Requirement
202
138
  none: false
203
- requirements:
204
- - - "="
205
- - !ruby/object:Gem::Version
206
- hash: 7
207
- segments:
208
- - 1
209
- - 4
210
- - 0
211
- version: 1.4.0
139
+ requirements:
140
+ - - =
141
+ - !ruby/object:Gem::Version
142
+ version: 2.2.2
143
+ type: :development
212
144
  prerelease: false
145
+ version_requirements: *75479780
146
+ - !ruby/object:Gem::Dependency
213
147
  name: bson
214
- version_requirements: *id013
215
- - !ruby/object:Gem::Dependency
216
- type: :development
217
- requirement: &id014 !ruby/object:Gem::Requirement
148
+ requirement: &75479190 !ruby/object:Gem::Requirement
218
149
  none: false
219
- requirements:
220
- - - "="
221
- - !ruby/object:Gem::Version
222
- hash: 7
223
- segments:
224
- - 1
225
- - 4
226
- - 0
150
+ requirements:
151
+ - - =
152
+ - !ruby/object:Gem::Version
227
153
  version: 1.4.0
154
+ type: :development
228
155
  prerelease: false
156
+ version_requirements: *75479190
157
+ - !ruby/object:Gem::Dependency
229
158
  name: bson_ext
230
- version_requirements: *id014
231
- - !ruby/object:Gem::Dependency
232
- type: :development
233
- requirement: &id015 !ruby/object:Gem::Requirement
159
+ requirement: &75478930 !ruby/object:Gem::Requirement
234
160
  none: false
235
- requirements:
236
- - - ">="
237
- - !ruby/object:Gem::Version
238
- hash: 3
239
- segments:
240
- - 0
241
- version: "0"
161
+ requirements:
162
+ - - =
163
+ - !ruby/object:Gem::Version
164
+ version: 1.4.0
165
+ type: :development
242
166
  prerelease: false
167
+ version_requirements: *75478930
168
+ - !ruby/object:Gem::Dependency
243
169
  name: fastercsv
244
- version_requirements: *id015
245
- description: This allows you to easily build datagrid aka data tables with sortable columns and filters
170
+ requirement: &75478570 !ruby/object:Gem::Requirement
171
+ none: false
172
+ requirements:
173
+ - - ! '>='
174
+ - !ruby/object:Gem::Version
175
+ version: '0'
176
+ type: :development
177
+ prerelease: false
178
+ version_requirements: *75478570
179
+ description: This allows you to easily build datagrid aka data tables with sortable
180
+ columns and filters
246
181
  email: agresso@gmail.com
247
182
  executables: []
248
-
249
183
  extensions: []
250
-
251
- extra_rdoc_files:
184
+ extra_rdoc_files:
252
185
  - LICENSE.txt
253
- files:
186
+ files:
254
187
  - .document
255
188
  - .rspec
256
189
  - Gemfile
@@ -311,37 +244,31 @@ files:
311
244
  - spec/support/simple_report.rb
312
245
  - spec/support/test_partials/_actions.html.erb
313
246
  homepage: http://github.com/bogdan/datagrid
314
- licenses:
247
+ licenses:
315
248
  - MIT
316
249
  post_install_message:
317
250
  rdoc_options: []
318
-
319
- require_paths:
251
+ require_paths:
320
252
  - lib
321
- required_ruby_version: !ruby/object:Gem::Requirement
253
+ required_ruby_version: !ruby/object:Gem::Requirement
322
254
  none: false
323
- requirements:
324
- - - ">="
325
- - !ruby/object:Gem::Version
326
- hash: 3
327
- segments:
255
+ requirements:
256
+ - - ! '>='
257
+ - !ruby/object:Gem::Version
258
+ version: '0'
259
+ segments:
328
260
  - 0
329
- version: "0"
330
- required_rubygems_version: !ruby/object:Gem::Requirement
261
+ hash: -141785713
262
+ required_rubygems_version: !ruby/object:Gem::Requirement
331
263
  none: false
332
- requirements:
333
- - - ">="
334
- - !ruby/object:Gem::Version
335
- hash: 3
336
- segments:
337
- - 0
338
- version: "0"
264
+ requirements:
265
+ - - ! '>='
266
+ - !ruby/object:Gem::Version
267
+ version: '0'
339
268
  requirements: []
340
-
341
269
  rubyforge_project:
342
- rubygems_version: 1.8.11
270
+ rubygems_version: 1.8.10
343
271
  signing_key:
344
272
  specification_version: 3
345
273
  summary: Ruby gem to create datagrids
346
274
  test_files: []
347
-