filterer 1.0.2 → 2.0.0.beta.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/filterer/active_record.rb +12 -7
- data/lib/filterer/base.rb +26 -19
- data/lib/filterer/version.rb +1 -1
- metadata +4 -33
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e4c80e1f46cf7a449a248bd2098a0cf25a2533f3
|
4
|
+
data.tar.gz: ed7d30e5cb98b8b906d8c92d5c0c0a351bcc4566
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f264ae332fd44cf42559a460a4455e58a737b106a5e3979473107fec4cafa6654b9606643990d5f9cb66b69554840030080fcc2c171fe9d7bd98cff5ae7a5ada
|
7
|
+
data.tar.gz: dfe8ec0acd0c53303729459f521a4c7314782d00de12c859e25b569e2b70dcb887b00101f9a4234d1e473cd5c9c4e3d7b71d8b2c124d2113651c9a124baf561d
|
@@ -2,18 +2,23 @@ module Filterer
|
|
2
2
|
module ActiveRecord
|
3
3
|
extend ActiveSupport::Concern
|
4
4
|
|
5
|
-
|
6
|
-
def
|
7
|
-
|
8
|
-
|
5
|
+
class_methods do
|
6
|
+
def filter(params = {}, opts = {})
|
7
|
+
delegate_to_filterer(:filter, params, opts)
|
8
|
+
end
|
9
|
+
|
10
|
+
def chain(params = {}, opts = {})
|
11
|
+
delegate_to_filterer(:chain, params, opts)
|
9
12
|
end
|
10
13
|
|
11
|
-
|
14
|
+
private
|
15
|
+
|
16
|
+
def delegate_to_filterer(method, params, opts)
|
12
17
|
filterer_class(opts[:filterer_class]).
|
13
|
-
|
18
|
+
send(method, params, { starting_query: all }.merge(opts))
|
14
19
|
end
|
15
20
|
|
16
|
-
def
|
21
|
+
def filterer_class(override)
|
17
22
|
if override
|
18
23
|
override.constantize
|
19
24
|
else
|
data/lib/filterer/base.rb
CHANGED
@@ -72,11 +72,12 @@ module Filterer
|
|
72
72
|
|
73
73
|
def initialize(params = {}, opts = {})
|
74
74
|
self.opts = opts
|
75
|
-
self.params = defaults.merge(params).
|
75
|
+
self.params = defaults.merge(parse_strong_parameters(params)).
|
76
|
+
with_indifferent_access
|
76
77
|
self.results = opts[:starting_query] || starting_query
|
77
78
|
self.results = apply_default_filters || results
|
78
79
|
add_params_to_query
|
79
|
-
|
80
|
+
self.results = ordered_results unless opts[:skip_ordering]
|
80
81
|
paginate_results unless opts[:skip_pagination]
|
81
82
|
extend_active_record_relation
|
82
83
|
end
|
@@ -137,7 +138,7 @@ module Filterer
|
|
137
138
|
method_name = "param_#{k}"
|
138
139
|
|
139
140
|
if respond_to?(method_name)
|
140
|
-
self.results = send(method_name, v)
|
141
|
+
self.results = send(method_name, v) || results
|
141
142
|
end
|
142
143
|
end
|
143
144
|
end
|
@@ -148,22 +149,14 @@ module Filterer
|
|
148
149
|
end
|
149
150
|
end
|
150
151
|
|
151
|
-
def
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
if sort_string
|
160
|
-
order_by_sort_option(sort_option.merge(
|
161
|
-
string_or_proc: sort_string
|
162
|
-
))
|
163
|
-
else
|
164
|
-
order_by_sort_option(filterer_default_sort_option)
|
165
|
-
end
|
166
|
-
end
|
152
|
+
def ordered_results
|
153
|
+
if sort_option && sort_option[:string_or_proc].is_a?(String)
|
154
|
+
order_by_sort_option(sort_option)
|
155
|
+
elsif sort_option && sort_option[:string_or_proc].is_a?(Proc)
|
156
|
+
order_by_sort_proc
|
157
|
+
else
|
158
|
+
order_by_sort_option(default_sort_option)
|
159
|
+
end
|
167
160
|
end
|
168
161
|
|
169
162
|
def per_page
|
@@ -194,6 +187,16 @@ module Filterer
|
|
194
187
|
end
|
195
188
|
end
|
196
189
|
|
190
|
+
def order_by_sort_proc
|
191
|
+
if (sort_string = sort_proc_to_string(sort_option))
|
192
|
+
order_by_sort_option(sort_option.merge(
|
193
|
+
string_or_proc: sort_string
|
194
|
+
))
|
195
|
+
else
|
196
|
+
order_by_sort_option(filterer_default_sort_option)
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
197
200
|
def order_by_sort_option(opt)
|
198
201
|
results.order %{
|
199
202
|
#{opt[:string_or_proc]}
|
@@ -238,5 +241,9 @@ module Filterer
|
|
238
241
|
end
|
239
242
|
end
|
240
243
|
end
|
244
|
+
|
245
|
+
def parse_strong_parameters(params)
|
246
|
+
params.try(:to_unsafe_h) || params
|
247
|
+
end
|
241
248
|
end
|
242
249
|
end
|
data/lib/filterer/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: filterer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0.beta.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Becker
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-09-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -94,20 +94,6 @@ dependencies:
|
|
94
94
|
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
|
-
- !ruby/object:Gem::Dependency
|
98
|
-
name: launchy
|
99
|
-
requirement: !ruby/object:Gem::Requirement
|
100
|
-
requirements:
|
101
|
-
- - ">="
|
102
|
-
- !ruby/object:Gem::Version
|
103
|
-
version: '0'
|
104
|
-
type: :development
|
105
|
-
prerelease: false
|
106
|
-
version_requirements: !ruby/object:Gem::Requirement
|
107
|
-
requirements:
|
108
|
-
- - ">="
|
109
|
-
- !ruby/object:Gem::Version
|
110
|
-
version: '0'
|
111
97
|
- !ruby/object:Gem::Dependency
|
112
98
|
name: pry
|
113
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -150,20 +136,6 @@ dependencies:
|
|
150
136
|
- - ">="
|
151
137
|
- !ruby/object:Gem::Version
|
152
138
|
version: '0'
|
153
|
-
- !ruby/object:Gem::Dependency
|
154
|
-
name: terminal-notifier-guard
|
155
|
-
requirement: !ruby/object:Gem::Requirement
|
156
|
-
requirements:
|
157
|
-
- - ">="
|
158
|
-
- !ruby/object:Gem::Version
|
159
|
-
version: '0'
|
160
|
-
type: :development
|
161
|
-
prerelease: false
|
162
|
-
version_requirements: !ruby/object:Gem::Requirement
|
163
|
-
requirements:
|
164
|
-
- - ">="
|
165
|
-
- !ruby/object:Gem::Version
|
166
|
-
version: '0'
|
167
139
|
description: Filterer lets your users easily filter results from your ActiveRecord
|
168
140
|
models.
|
169
141
|
email:
|
@@ -199,9 +171,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
199
171
|
version: '0'
|
200
172
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
201
173
|
requirements:
|
202
|
-
- - "
|
174
|
+
- - ">"
|
203
175
|
- !ruby/object:Gem::Version
|
204
|
-
version:
|
176
|
+
version: 1.3.1
|
205
177
|
requirements: []
|
206
178
|
rubyforge_project:
|
207
179
|
rubygems_version: 2.5.1
|
@@ -209,4 +181,3 @@ signing_key:
|
|
209
181
|
specification_version: 4
|
210
182
|
summary: Easily filter results from your ActiveRecord models.
|
211
183
|
test_files: []
|
212
|
-
has_rdoc:
|