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 +4 -4
- data/lib/smart_listing.rb +16 -4
- data/lib/smart_listing/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ebac27f2385c61936cbfe49ef0e7922b9748aae2a4fd35fc0b8df3a1ce4955b1
|
4
|
+
data.tar.gz: 52fe90ebcc6fb39f5b3201a39ca99177430c3adb1ab9ee4c538a051829acb411
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e8dc0079b18c666332c12885629a0e203bdb18f52897ad81cc6157f0cf67a6e8ed551a6eb2c171192a71cbf8f5e1a0066382cac657623c6461b846e69fcfc2a3
|
7
|
+
data.tar.gz: 629f3483ef13c5b5042f051a303a0d6b4f3b480ada5bde1dc5dc6d1932babc1944c7fa74a72bcd046c0f7a4f4f042f0dfe41f1723a996370d763162f5e53db3c
|
data/lib/smart_listing.rb
CHANGED
@@ -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
|
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 =
|
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
|
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.
|
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:
|
11
|
+
date: 2019-07-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|