incline 0.2.22 → 0.2.23

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: 9a1e49384b7901f87a814ee60d71b0851ddc7f7b
4
- data.tar.gz: 111391691fad01b40f655ee7cef3a998c1863068
3
+ metadata.gz: 8e361fba9f1b1198c39aac4dc2a24d7f61dee689
4
+ data.tar.gz: 88d60394ae9ff47ae5517aba022e1e0890f57fcb
5
5
  SHA512:
6
- metadata.gz: 6fa77414d22418a5866ee05c1a3a6b4361ff2a4a48dfa889a63599999afb355503e492911e338f895490492ad132f02cc948c53eed0ac8917ef54a10fe37521b
7
- data.tar.gz: c64ce83ca35c5132ba98e5e46f615327bddf7f00dbf4f523b510b7a0fe53118cbd97fafb66825124d08881a8fefbaeb5ced2dfb93a109891132a5287ed73f736
6
+ metadata.gz: 55f9e505070563fcb301328bfe2acb09490cdce9e726287ba1aa60a91072f89cc5ce09d526020500b586eb01dc79004a445e731408b9bda4812d564d352f1d81
7
+ data.tar.gz: e9e9006297346b190372be28398058cc9f5c5d08a62f53ad471d56946dbe9de1229b8950cc4d99ad29dae854c15f197d9c9a99233be8e38fd266471c378f16bd
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- incline (0.2.22)
4
+ incline (0.2.23)
5
5
  ansi (~> 1.5.0)
6
6
  bcrypt
7
7
  bootstrap-sass
@@ -58,7 +58,7 @@ GEM
58
58
  tzinfo (~> 1.1)
59
59
  ansi (1.5.0)
60
60
  arel (6.0.4)
61
- autoprefixer-rails (7.1.5)
61
+ autoprefixer-rails (7.1.6)
62
62
  execjs
63
63
  bcrypt (3.1.11)
64
64
  bootstrap-sass (3.3.7)
@@ -209,13 +209,19 @@ module Incline
209
209
 
210
210
  dataset = load_records(relation, false)
211
211
  return -1 if dataset.blank?
212
+
213
+ first_item = dataset.first
214
+ klass = first_item.class
215
+
216
+ id_field = klass.respond_to?('primary_key') ? klass.primary_key : nil
217
+ id_field ||= first_item.respond_to?('id') ? 'id' : nil
212
218
 
213
- return -1 unless dataset.first.respond_to?(:id)
219
+ return -1 unless id_field
214
220
  if locate_id.is_a?(::Numeric)
215
- dataset.index{|item| item.id == locate_id} || -1
221
+ dataset.index{|item| item.send(id_field) == locate_id} || -1
216
222
  else
217
223
  loc_id = locate_id.to_s.downcase
218
- dataset.index{|item| item.id.to_s.downcase == loc_id} || -1
224
+ dataset.index{|item| item.send(id_field).to_s.downcase == loc_id} || -1
219
225
  end
220
226
 
221
227
  end
@@ -240,15 +246,19 @@ module Incline
240
246
  # store the unfiltered count.
241
247
  @config[:records_total] = relation.count
242
248
 
243
- # If any of these is true, then filtering must be done locally in our code.
244
- filter_local = (
245
- # main search is a regex.
246
- search.is_a?(::Regexp) ||
247
- # one or more column searches is a regex.
248
- columns.select{|c| c[:search].is_a?(::Regexp)}.any? ||
249
- # one or more searchable columns is not in the database model.
250
- columns.reject {|c| !c[:searchable] || relation.model.column_names.include?(c[:name].to_s)}.any?
251
- )
249
+ # If we have search parameters and any of the search parameters is a regular expression or
250
+ # one or more columns being searched is not a database column, then filtering must be done
251
+ # locally.
252
+ filter_local =
253
+ !(search.blank? && columns.reject{|c| c[:search].blank? }.blank?) &&
254
+ (
255
+ # main search is a regex.
256
+ search.is_a?(::Regexp) ||
257
+ # one or more column searches is a regex.
258
+ columns.select{|c| c[:search].is_a?(::Regexp)}.any? ||
259
+ # one or more searchable columns is not in the database model
260
+ columns.reject {|c| !c[:searchable] || relation.model.column_names.include?(c[:name].to_s) }.any?
261
+ )
252
262
 
253
263
  Incline::Log::debug "Filtering will be done #{filter_local ? 'application' : 'database'}-side."
254
264
 
@@ -1,3 +1,3 @@
1
1
  module Incline
2
- VERSION = "0.2.22"
2
+ VERSION = "0.2.23"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: incline
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.22
4
+ version: 0.2.23
5
5
  platform: ruby
6
6
  authors:
7
7
  - Beau Barker
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-10-24 00:00:00.000000000 Z
11
+ date: 2017-10-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails