smart_listing 1.2.2 → 1.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d094a24f3cf879ec07471fa78e42f6d7923476971f03f0b3d0ffdc4243488e28
4
- data.tar.gz: 44f9ec23a184ff3c3df4fa2af4e053115dc78830036fba5f5584733c38b03977
3
+ metadata.gz: ebac27f2385c61936cbfe49ef0e7922b9748aae2a4fd35fc0b8df3a1ce4955b1
4
+ data.tar.gz: 52fe90ebcc6fb39f5b3201a39ca99177430c3adb1ab9ee4c538a051829acb411
5
5
  SHA512:
6
- metadata.gz: 5c71f8202ab047e5727f8f0ca04aaa7d940aaf1f304758690905cc4be8f96ecb32cd3de1e616d5e355c9e21773b57d7ace88987c0ced8d7e09599fa3d700c627
7
- data.tar.gz: 7c7377b916ab03f30a4992f7fa37241f474033a8aa38320e27e454ebbd01617d49ac480a4879b8f2f88c38023633a66b155939e8dfff000389096d50d745ce9c
6
+ metadata.gz: e8dc0079b18c666332c12885629a0e203bdb18f52897ad81cc6157f0cf67a6e8ed551a6eb2c171192a71cbf8f5e1a0066382cac657623c6461b846e69fcfc2a3
7
+ data.tar.gz: 629f3483ef13c5b5042f051a303a0d6b4f3b480ada5bde1dc5dc6d1932babc1944c7fa74a72bcd046c0f7a4f4f042f0dfe41f1723a996370d763162f5e53db3c
@@ -24,6 +24,10 @@ module SmartListing
24
24
  attr_reader :name, :collection, :options, :per_page, :sort, :page, :partial, :count, :params
25
25
  # Params that should not be visible in pagination links (pages, per-page, sorting, etc.)
26
26
  UNSAFE_PARAMS = [:authenticity_token, :commit, :utf8, :_method, :script_name].freeze
27
+ # For fast-check, like:
28
+ # puts variable if ALLOWED_DIRECTIONS[variable]
29
+ ALLOWED_DIRECTIONS = Hash[['asc', 'desc', ''].map { |d| [d, true] }].freeze
30
+ private_constant :ALLOWED_DIRECTIONS
27
31
 
28
32
  def initialize name, collection, options = {}
29
33
  @name = name
@@ -200,16 +204,24 @@ module SmartListing
200
204
  sort = nil
201
205
 
202
206
  if @options[:sort_attributes] == :implicit
203
- sort = sort_params.dup if sort_params.present?
207
+ return sort if sort_params.blank?
208
+
209
+ sort_params.map do |attr, dir|
210
+ key = attr.to_s if @options[:array] || @collection.klass.attribute_method?(attr)
211
+ if key && ALLOWED_DIRECTIONS[dir.to_s]
212
+ sort ||= {}
213
+ sort[key] = dir.to_s
214
+ end
215
+ end
204
216
  elsif @options[:sort_attributes]
205
217
  @options[:sort_attributes].each do |a|
206
218
  k, v = a
207
219
  if sort_params && sort_params[k.to_s]
208
- dir = ["asc", "desc", ""].delete(sort_params[k.to_s])
220
+ dir = sort_params[k.to_s].to_s
209
221
 
210
- if dir
222
+ if ALLOWED_DIRECTIONS[dir]
211
223
  sort ||= {}
212
- sort[k] = dir
224
+ sort[k] = dir.to_s
213
225
  end
214
226
  end
215
227
  end
@@ -1,3 +1,3 @@
1
1
  module SmartListing
2
- VERSION = "1.2.2"
2
+ VERSION = "1.2.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smart_listing
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.2
4
+ version: 1.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sology
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-03-11 00:00:00.000000000 Z
11
+ date: 2019-07-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails