datagrid 1.4.4 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 652aabb87668eb9c636d3a0b03249f79f8df4c1b
4
- data.tar.gz: 71de05a4267561305a3e2badc2aa33e1eb88cf35
3
+ metadata.gz: 6dff6baaffd8e634c9e7d93754752f3389860060
4
+ data.tar.gz: f4f7c4d3092942e52f5d9c365c914e32b36b4fb3
5
5
  SHA512:
6
- metadata.gz: 5db3557c03071721e24d355ac939ab76f29167c252c9cfda160a618e4f1b7737dfc241c808de1ccd1a75a8c7b2a9c16490a1d96500065c196413f6548e47b9ed
7
- data.tar.gz: c34e6068303b5aa6d351869fe7d734cc4034305de5e649ea9480e74ec3dddb39b2d34ff16277f1f4a792c670d36b09cf8b826a0888a8d23906c1682facd68ac9
6
+ metadata.gz: aa1c966c59b28eb7247e8fb8c660765e22608f3308153d3715610e5e45590b210cef2cd951dc1fe8f4e1489c3b4894623fd057b90f66be9b184b16bb510896de
7
+ data.tar.gz: 8a673590ea08d5618fac8f984ee56c5fbd61d8287aacf37caf7ff3cb2090c8b448d217603a67485aa28fc1d8402fe5fb8536cc1c75976369061a0362298e7829
data/.travis.yml CHANGED
@@ -1,7 +1,6 @@
1
1
  language: ruby
2
2
  #bundler_args: --without development
3
3
  rvm:
4
- - 1.9.3
5
4
  - 2.0.0
6
5
  - 2.1.1
7
6
  - 2.2.0
data/Gemfile CHANGED
@@ -5,11 +5,11 @@ gem "rails", ">= 3.2.22.2"
5
5
  group :development do
6
6
 
7
7
  gem "bundler"
8
- gem "jeweler"
8
+ gem "jeweler", github: "technicalpickles/jeweler"
9
9
 
10
10
 
11
11
  gem "debugger", :platform => :ruby_19
12
- gem "byebug", :platform => [:ruby_20, :ruby_21, :ruby_22, :ruby_23] & Bundler::Dsl::VALID_PLATFORMS
12
+ gem "pry-byebug", :platform => [:ruby_20, :ruby_21, :ruby_22, :ruby_23] & Bundler::Dsl::VALID_PLATFORMS
13
13
 
14
14
  gem "rspec", ">= 3"
15
15
  gem "nokogiri" # used to test html output
data/Rakefile CHANGED
@@ -21,6 +21,7 @@ Jeweler::Tasks.new do |gem|
21
21
  gem.description = %Q{This allows you to easily build datagrid aka data tables with sortable columns and filters}
22
22
  gem.email = "agresso@gmail.com"
23
23
  gem.authors = ["Bogdan Gusiev"]
24
+ gem.required_ruby_version = '>= 2.0'
24
25
  # dependencies defined in Gemfile
25
26
  end
26
27
  Jeweler::RubygemsDotOrgTasks.new
data/Readme.markdown CHANGED
@@ -20,6 +20,12 @@ Ruby library that helps you to build and represent table-like data with:
20
20
 
21
21
  [Create an issue](https://github.com/bogdan/datagrid/issues/new) if you want more.
22
22
 
23
+
24
+ ### Dependencies
25
+
26
+ * Ruby >= 2.0
27
+ * Rails >= 3.2
28
+
23
29
  ### Live Demo
24
30
 
25
31
  [Datagrid DEMO application](http://datagrid.herokuapp.com) is available live!
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.4.4
1
+ 1.5.0
data/datagrid.gemspec CHANGED
@@ -2,18 +2,18 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: datagrid 1.4.4 ruby lib
5
+ # stub: datagrid 1.5.0 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
- s.name = "datagrid"
9
- s.version = "1.4.4"
8
+ s.name = "datagrid".freeze
9
+ s.version = "1.5.0"
10
10
 
11
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
- s.require_paths = ["lib"]
13
- s.authors = ["Bogdan Gusiev"]
14
- s.date = "2016-07-22"
15
- s.description = "This allows you to easily build datagrid aka data tables with sortable columns and filters"
16
- s.email = "agresso@gmail.com"
11
+ s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
12
+ s.require_paths = ["lib".freeze]
13
+ s.authors = ["Bogdan Gusiev".freeze]
14
+ s.date = "2016-10-13"
15
+ s.description = "This allows you to easily build datagrid aka data tables with sortable columns and filters".freeze
16
+ s.email = "agresso@gmail.com".freeze
17
17
  s.extra_rdoc_files = [
18
18
  "LICENSE.txt"
19
19
  ]
@@ -126,57 +126,97 @@ Gem::Specification.new do |s|
126
126
  "templates/grid.rb.erb",
127
127
  "templates/index.html.erb"
128
128
  ]
129
- s.homepage = "http://github.com/bogdan/datagrid"
130
- s.licenses = ["MIT"]
131
- s.rubygems_version = "2.5.1"
132
- s.summary = "Ruby gem to create datagrids"
129
+ s.homepage = "http://github.com/bogdan/datagrid".freeze
130
+ s.licenses = ["MIT".freeze]
131
+ s.required_ruby_version = Gem::Requirement.new(">= 2.0".freeze)
132
+ s.rubygems_version = "2.6.7".freeze
133
+ s.summary = "Ruby gem to create datagrids".freeze
133
134
 
134
135
  if s.respond_to? :specification_version then
135
136
  s.specification_version = 4
136
137
 
137
138
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
138
- s.add_runtime_dependency(%q<rails>, [">= 3.2.22.2"])
139
- s.add_development_dependency(%q<bundler>, [">= 0"])
140
- s.add_development_dependency(%q<jeweler>, [">= 0"])
141
- s.add_development_dependency(%q<debugger>, [">= 0"])
142
- s.add_development_dependency(%q<byebug>, [">= 0"])
143
- s.add_development_dependency(%q<rspec>, [">= 3"])
144
- s.add_development_dependency(%q<nokogiri>, [">= 0"])
145
- s.add_development_dependency(%q<sqlite3>, [">= 0"])
146
- s.add_development_dependency(%q<sequel>, [">= 0"])
147
- s.add_development_dependency(%q<mongoid>, ["= 3.1.7"])
148
- s.add_development_dependency(%q<mongo_mapper>, ["~> 0.13.0"])
149
- s.add_development_dependency(%q<bson>, [">= 0"])
150
- s.add_development_dependency(%q<bson_ext>, [">= 0"])
139
+ s.add_runtime_dependency(%q<rails>.freeze, [">= 3.2.22.2"])
140
+ s.add_runtime_dependency(%q<bundler>.freeze, [">= 0"])
141
+ s.add_runtime_dependency(%q<jeweler>.freeze, [">= 0"])
142
+ s.add_runtime_dependency(%q<debugger>.freeze, [">= 0"])
143
+ s.add_runtime_dependency(%q<pry-byebug>.freeze, [">= 0"])
144
+ s.add_runtime_dependency(%q<rspec>.freeze, [">= 3"])
145
+ s.add_runtime_dependency(%q<nokogiri>.freeze, [">= 0"])
146
+ s.add_runtime_dependency(%q<sqlite3>.freeze, [">= 0"])
147
+ s.add_runtime_dependency(%q<sequel>.freeze, [">= 0"])
148
+ s.add_runtime_dependency(%q<mongoid>.freeze, ["= 3.1.7"])
149
+ s.add_runtime_dependency(%q<mongo_mapper>.freeze, ["~> 0.13.0"])
150
+ s.add_runtime_dependency(%q<bson>.freeze, [">= 0"])
151
+ s.add_runtime_dependency(%q<bson_ext>.freeze, [">= 0"])
152
+ s.add_development_dependency(%q<rails>.freeze, [">= 3.2.22.2"])
153
+ s.add_development_dependency(%q<bundler>.freeze, [">= 0"])
154
+ s.add_development_dependency(%q<jeweler>.freeze, [">= 0"])
155
+ s.add_development_dependency(%q<debugger>.freeze, [">= 0"])
156
+ s.add_development_dependency(%q<pry-byebug>.freeze, [">= 0"])
157
+ s.add_development_dependency(%q<rspec>.freeze, [">= 3"])
158
+ s.add_development_dependency(%q<nokogiri>.freeze, [">= 0"])
159
+ s.add_development_dependency(%q<sqlite3>.freeze, [">= 0"])
160
+ s.add_development_dependency(%q<sequel>.freeze, [">= 0"])
161
+ s.add_development_dependency(%q<mongoid>.freeze, ["= 3.1.7"])
162
+ s.add_development_dependency(%q<mongo_mapper>.freeze, ["~> 0.13.0"])
163
+ s.add_development_dependency(%q<bson>.freeze, [">= 0"])
164
+ s.add_development_dependency(%q<bson_ext>.freeze, [">= 0"])
151
165
  else
152
- s.add_dependency(%q<rails>, [">= 3.2.22.2"])
153
- s.add_dependency(%q<bundler>, [">= 0"])
154
- s.add_dependency(%q<jeweler>, [">= 0"])
155
- s.add_dependency(%q<debugger>, [">= 0"])
156
- s.add_dependency(%q<byebug>, [">= 0"])
157
- s.add_dependency(%q<rspec>, [">= 3"])
158
- s.add_dependency(%q<nokogiri>, [">= 0"])
159
- s.add_dependency(%q<sqlite3>, [">= 0"])
160
- s.add_dependency(%q<sequel>, [">= 0"])
161
- s.add_dependency(%q<mongoid>, ["= 3.1.7"])
162
- s.add_dependency(%q<mongo_mapper>, ["~> 0.13.0"])
163
- s.add_dependency(%q<bson>, [">= 0"])
164
- s.add_dependency(%q<bson_ext>, [">= 0"])
166
+ s.add_dependency(%q<rails>.freeze, [">= 3.2.22.2"])
167
+ s.add_dependency(%q<bundler>.freeze, [">= 0"])
168
+ s.add_dependency(%q<jeweler>.freeze, [">= 0"])
169
+ s.add_dependency(%q<debugger>.freeze, [">= 0"])
170
+ s.add_dependency(%q<pry-byebug>.freeze, [">= 0"])
171
+ s.add_dependency(%q<rspec>.freeze, [">= 3"])
172
+ s.add_dependency(%q<nokogiri>.freeze, [">= 0"])
173
+ s.add_dependency(%q<sqlite3>.freeze, [">= 0"])
174
+ s.add_dependency(%q<sequel>.freeze, [">= 0"])
175
+ s.add_dependency(%q<mongoid>.freeze, ["= 3.1.7"])
176
+ s.add_dependency(%q<mongo_mapper>.freeze, ["~> 0.13.0"])
177
+ s.add_dependency(%q<bson>.freeze, [">= 0"])
178
+ s.add_dependency(%q<bson_ext>.freeze, [">= 0"])
179
+ s.add_dependency(%q<rails>.freeze, [">= 3.2.22.2"])
180
+ s.add_dependency(%q<bundler>.freeze, [">= 0"])
181
+ s.add_dependency(%q<jeweler>.freeze, [">= 0"])
182
+ s.add_dependency(%q<debugger>.freeze, [">= 0"])
183
+ s.add_dependency(%q<pry-byebug>.freeze, [">= 0"])
184
+ s.add_dependency(%q<rspec>.freeze, [">= 3"])
185
+ s.add_dependency(%q<nokogiri>.freeze, [">= 0"])
186
+ s.add_dependency(%q<sqlite3>.freeze, [">= 0"])
187
+ s.add_dependency(%q<sequel>.freeze, [">= 0"])
188
+ s.add_dependency(%q<mongoid>.freeze, ["= 3.1.7"])
189
+ s.add_dependency(%q<mongo_mapper>.freeze, ["~> 0.13.0"])
190
+ s.add_dependency(%q<bson>.freeze, [">= 0"])
191
+ s.add_dependency(%q<bson_ext>.freeze, [">= 0"])
165
192
  end
166
193
  else
167
- s.add_dependency(%q<rails>, [">= 3.2.22.2"])
168
- s.add_dependency(%q<bundler>, [">= 0"])
169
- s.add_dependency(%q<jeweler>, [">= 0"])
170
- s.add_dependency(%q<debugger>, [">= 0"])
171
- s.add_dependency(%q<byebug>, [">= 0"])
172
- s.add_dependency(%q<rspec>, [">= 3"])
173
- s.add_dependency(%q<nokogiri>, [">= 0"])
174
- s.add_dependency(%q<sqlite3>, [">= 0"])
175
- s.add_dependency(%q<sequel>, [">= 0"])
176
- s.add_dependency(%q<mongoid>, ["= 3.1.7"])
177
- s.add_dependency(%q<mongo_mapper>, ["~> 0.13.0"])
178
- s.add_dependency(%q<bson>, [">= 0"])
179
- s.add_dependency(%q<bson_ext>, [">= 0"])
194
+ s.add_dependency(%q<rails>.freeze, [">= 3.2.22.2"])
195
+ s.add_dependency(%q<bundler>.freeze, [">= 0"])
196
+ s.add_dependency(%q<jeweler>.freeze, [">= 0"])
197
+ s.add_dependency(%q<debugger>.freeze, [">= 0"])
198
+ s.add_dependency(%q<pry-byebug>.freeze, [">= 0"])
199
+ s.add_dependency(%q<rspec>.freeze, [">= 3"])
200
+ s.add_dependency(%q<nokogiri>.freeze, [">= 0"])
201
+ s.add_dependency(%q<sqlite3>.freeze, [">= 0"])
202
+ s.add_dependency(%q<sequel>.freeze, [">= 0"])
203
+ s.add_dependency(%q<mongoid>.freeze, ["= 3.1.7"])
204
+ s.add_dependency(%q<mongo_mapper>.freeze, ["~> 0.13.0"])
205
+ s.add_dependency(%q<bson>.freeze, [">= 0"])
206
+ s.add_dependency(%q<bson_ext>.freeze, [">= 0"])
207
+ s.add_dependency(%q<rails>.freeze, [">= 3.2.22.2"])
208
+ s.add_dependency(%q<bundler>.freeze, [">= 0"])
209
+ s.add_dependency(%q<jeweler>.freeze, [">= 0"])
210
+ s.add_dependency(%q<debugger>.freeze, [">= 0"])
211
+ s.add_dependency(%q<pry-byebug>.freeze, [">= 0"])
212
+ s.add_dependency(%q<rspec>.freeze, [">= 3"])
213
+ s.add_dependency(%q<nokogiri>.freeze, [">= 0"])
214
+ s.add_dependency(%q<sqlite3>.freeze, [">= 0"])
215
+ s.add_dependency(%q<sequel>.freeze, [">= 0"])
216
+ s.add_dependency(%q<mongoid>.freeze, ["= 3.1.7"])
217
+ s.add_dependency(%q<mongo_mapper>.freeze, ["~> 0.13.0"])
218
+ s.add_dependency(%q<bson>.freeze, [">= 0"])
219
+ s.add_dependency(%q<bson_ext>.freeze, [">= 0"])
180
220
  end
181
221
  end
182
222
 
@@ -119,6 +119,7 @@ module Datagrid
119
119
  # * <tt>:after</tt> - determines the position of this column, by adding it after the column passed here
120
120
  # * <tt>:if</tt> - the column is shown if the reult of calling this argument is true
121
121
  # * <tt>:unless</tt> - the column is shown unless the reult of calling this argument is true
122
+ # * <tt>:preload</tt> - spefies which associations of the scope should be preloaded for this column
122
123
  #
123
124
  # See: https://github.com/bogdan/datagrid/wiki/Columns for examples
124
125
  def column(name, options_or_query = {}, options = {}, &block)
@@ -225,7 +226,9 @@ module Datagrid
225
226
  args.compact!
226
227
  args.map!(&:to_sym)
227
228
  columns.select do |column|
228
- (!options[:data] || column.data?) && (!options[:html] || column.html?) && (column.mandatory? || args.empty? || args.include?(column.name))
229
+ (!options[:data] || column.data?) &&
230
+ (!options[:html] || column.html?) &&
231
+ (column.mandatory? || args.empty? || args.include?(column.name))
229
232
  end
230
233
  end
231
234
 
@@ -240,7 +243,9 @@ module Datagrid
240
243
  model.send(name)
241
244
  end
242
245
  position = Datagrid::Utils.extract_position_from_options(columns, options)
243
- column = Datagrid::Columns::Column.new(self, name, query, default_column_options.merge(options), &block)
246
+ column = Datagrid::Columns::Column.new(
247
+ self, name, query, default_column_options.merge(options), &block
248
+ )
244
249
  columns.insert(position, column)
245
250
  end
246
251
 
@@ -256,7 +261,11 @@ module Datagrid
256
261
  module InstanceMethods
257
262
 
258
263
  def assets
259
- driver.append_column_queries(super, columns.select(&:query))
264
+ append_column_preload(
265
+ driver.append_column_queries(
266
+ super, columns.select(&:query)
267
+ )
268
+ )
260
269
  end
261
270
 
262
271
  # Returns <tt>Array</tt> of human readable column names. See also "Localization" section
@@ -513,6 +522,12 @@ module Datagrid
513
522
 
514
523
  protected
515
524
 
525
+ def append_column_preload(scope)
526
+ columns.inject(scope) do |current, column|
527
+ column.append_preload(current)
528
+ end
529
+ end
530
+
516
531
  def cache(column, asset, type)
517
532
  @cache ||= {}
518
533
  unless cached?
@@ -69,7 +69,7 @@ class Datagrid::Columns::Column
69
69
  if options.has_key?(:order) && options[:order] != true
70
70
  self.options[:order]
71
71
  else
72
- grid_class.driver.default_order(grid_class.scope, name)
72
+ driver.default_order(grid_class.scope, name)
73
73
  end
74
74
  end
75
75
 
@@ -107,8 +107,7 @@ class Datagrid::Columns::Column
107
107
  end
108
108
 
109
109
  def enabled?(grid)
110
- column_availability(grid, options[:if], true) &&
111
- !column_availability(grid, options[:unless], false)
110
+ ::Datagrid::Utils.process_availability(grid, options[:if], options[:unless])
112
111
  end
113
112
 
114
113
  def inspect
@@ -133,21 +132,36 @@ class Datagrid::Columns::Column
133
132
  grid.generic_value(self, model)
134
133
  end
135
134
 
136
- private
137
- def column_availability(grid, option, default)
138
- case option
139
- when nil
140
- default
141
- when Proc
142
- option.call(grid)
143
- when Symbol, String
144
- grid.send(option.to_sym)
135
+ def append_preload(scope)
136
+ return scope unless preload
137
+ if preload.respond_to?(:call)
138
+ return scope unless preload
139
+ if preload.arity == 1
140
+ preload.call(scope)
141
+ else
142
+ scope.instance_exec(&preload)
143
+ end
145
144
  else
146
- raise Datagrid::ConfigurationError, "Incorrect column availability option: #{option.insepct}"
145
+ driver.default_preload(scope, preload)
147
146
  end
148
147
  end
149
148
 
149
+ def preload
150
+ preload = options[:preload]
151
+
152
+ if [nil, true].include?(preload) && driver.can_preload?(driver.to_scope(grid_class.scope), name)
153
+ name
154
+ else
155
+ preload
156
+ end
157
+
158
+ end
159
+
150
160
  def callable(value)
151
161
  value.respond_to?(:call) ? value.call : value
152
162
  end
163
+
164
+ def driver
165
+ grid_class.driver
166
+ end
153
167
  end
data/lib/datagrid/core.rb CHANGED
@@ -35,7 +35,11 @@ module Datagrid
35
35
  # Defines a scope at class level
36
36
  def scope(&block)
37
37
  if block
38
- self.scope_value = block
38
+ current_scope = scope_value
39
+ self.scope_value = proc {
40
+ Datagrid::Utils.apply_args(current_scope ? current_scope.call : nil, &block)
41
+ }
42
+ self
39
43
  else
40
44
  check_scope_defined!
41
45
  scope_value.call
@@ -144,7 +148,12 @@ module Datagrid
144
148
 
145
149
  # Resets current instance scope to default scope defined in a class
146
150
  def reset_scope
147
- scope(&self.class.scope_value)
151
+ self.scope_value = self.class.scope_value
152
+ end
153
+
154
+ # Returns true if the scope was redefined for this instance of grid object
155
+ def redefined_scope?
156
+ self.class.scope_value != scope_value
148
157
  end
149
158
 
150
159
  def driver #:nodoc:
@@ -105,6 +105,14 @@ module Datagrid
105
105
  scope
106
106
  end
107
107
 
108
+ def default_preload(scope, value)
109
+ raise NotImplementedError
110
+ end
111
+
112
+ def can_preload?(scope, association)
113
+ raise NotImplementedError
114
+ end
115
+
108
116
  protected
109
117
  def timestamp_class?(klass)
110
118
  TIMESTAMP_CLASSES.include?(klass)
@@ -116,6 +116,14 @@ module Datagrid
116
116
  asset.id || raise(NotImplementedError)
117
117
  end
118
118
 
119
+ def default_preload(scope, value)
120
+ scope.preload(value)
121
+ end
122
+
123
+ def can_preload?(scope, association)
124
+ !! scope.klass.reflect_on_association(association)
125
+ end
126
+
119
127
  protected
120
128
 
121
129
  def prefix_table_name(scope, field)
@@ -68,10 +68,14 @@ module Datagrid
68
68
  def batch_each(scope, batch_size, &block)
69
69
  scope.each(&block)
70
70
  end
71
-
71
+
72
72
  def default_cache_key(asset)
73
73
  asset
74
74
  end
75
+
76
+ def can_preload?(scope, association)
77
+ false
78
+ end
75
79
  end
76
80
  end
77
81
  end
@@ -71,6 +71,14 @@ module Datagrid
71
71
  def default_cache_key(asset)
72
72
  raise NotImplementedError
73
73
  end
74
+
75
+ def default_preload(scope, value)
76
+ raise NotImplementedError
77
+ end
78
+
79
+ def can_preload?(scope, association)
80
+ false
81
+ end
74
82
  end
75
83
  end
76
84
  end
@@ -94,6 +94,15 @@ module Datagrid
94
94
  def default_cache_key(asset)
95
95
  asset.id || raise(NotImplementedError)
96
96
  end
97
+
98
+ def default_preload(scope, value)
99
+ scope.includes(value)
100
+ end
101
+
102
+ def can_preload?(scope, association)
103
+ !! scope.klass.reflect_on_association(association)
104
+ end
105
+
97
106
  end
98
107
  end
99
108
  end