activerecord-filter 5.0.0.rc1 → 5.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/active_record/filter.rb +17 -8
- data/lib/active_record/filter/version.rb +1 -1
- metadata +64 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4fdf28c6e50c3f887b05980cf00e7070bab91b91
|
4
|
+
data.tar.gz: 491ce24013f744189405c9a92845a7f275b7ca23
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fa8bec5eb557ce931bd580d0a32e4cf014c734f22a32652d5778aa247220bf8dee24efa1af7db6ce44ef73134ecb8066d32bfed19a787fa844ed82d5e95033e7
|
7
|
+
data.tar.gz: b9b9867c21937111b5770269dbe6b6327cd0eb626974c23f898e718d1eb6a6132ecdaabd0cfb2a836f374a161b4b25b4cb89a1dfe2d2f6ba6a0d107e3dc22c62
|
data/lib/active_record/filter.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'active_record'
|
2
2
|
require 'arel/extensions'
|
3
|
+
require 'action_controller/metal/strong_parameters'
|
3
4
|
|
4
5
|
class ActiveRecord::UnkownFilterError < NoMethodError
|
5
6
|
attr_reader :klass, :filter
|
@@ -26,7 +27,8 @@ module ActiveRecord::Filter
|
|
26
27
|
resource = all
|
27
28
|
return resource unless filters
|
28
29
|
|
29
|
-
|
30
|
+
case filters
|
31
|
+
when Hash, ActionController::Parameters
|
30
32
|
filters.each do |key, value|
|
31
33
|
if @filters[key]
|
32
34
|
#TODO add test for this... not sure how rails does this lambda call,
|
@@ -36,7 +38,7 @@ module ActiveRecord::Filter
|
|
36
38
|
resource = resource.filter_for(key, value, options)
|
37
39
|
end
|
38
40
|
end
|
39
|
-
|
41
|
+
when Integer, Array
|
40
42
|
resource = resource.filter_for(:id, filters, options)
|
41
43
|
end
|
42
44
|
|
@@ -53,12 +55,18 @@ module ActiveRecord::Filter
|
|
53
55
|
if relation = reflect_on_association(key)
|
54
56
|
self.send("filter_for_#{relation.macro}", relation, value)
|
55
57
|
else
|
56
|
-
#
|
57
|
-
|
58
|
-
|
59
|
-
all.send("filter_for_#{value.values.first.class.to_s.downcase}", key, value, options)
|
58
|
+
# Custom filter, try to guess based on value
|
59
|
+
method = if value.is_a?(Hash) || value.is_a?(ActionController::Parameters)
|
60
|
+
"filter_for_#{value.values.first.class.to_s.downcase}"
|
60
61
|
else
|
61
|
-
|
62
|
+
"filter_for_#{value.class.to_s.downcase}"
|
63
|
+
end
|
64
|
+
|
65
|
+
puts method, all.respond_to?(method)
|
66
|
+
if all.respond_to?(method)
|
67
|
+
all.send(method, key, value, options)
|
68
|
+
else
|
69
|
+
raise ActiveRecord::UnkownFilterError.new(self, key)
|
62
70
|
end
|
63
71
|
end
|
64
72
|
end
|
@@ -68,6 +76,7 @@ module ActiveRecord::Filter
|
|
68
76
|
filter_for_geometry: :itself,
|
69
77
|
filter_for_datetime: :to_datetime,
|
70
78
|
filter_for_integer: :to_i,
|
79
|
+
filter_for_fixnum: :to_i,
|
71
80
|
filter_for_text: :itself,
|
72
81
|
filter_for_boolean: :itself,
|
73
82
|
filter_for_string: :itself,
|
@@ -77,7 +86,7 @@ module ActiveRecord::Filter
|
|
77
86
|
}.each_pair do |method_name, send_method|
|
78
87
|
define_method(method_name) do |column, value, options={}|
|
79
88
|
table = options[:table_alias] ? arel_table.alias(options[:table_alias]) : arel_table
|
80
|
-
|
89
|
+
|
81
90
|
if value.is_a?(Hash) || value.class.name == "ActionController::Parameters".freeze
|
82
91
|
resource = all
|
83
92
|
value.each_pair do |key, value|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord-filter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.0.0
|
4
|
+
version: 5.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jon Bracy
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-08-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -16,56 +16,100 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 5.0
|
19
|
+
version: '5.0'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 5.0.0
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '5.0'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 5.0.0
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: actionpack
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '5.0'
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: 5.0.0
|
20
43
|
type: :runtime
|
21
44
|
prerelease: false
|
22
45
|
version_requirements: !ruby/object:Gem::Requirement
|
23
46
|
requirements:
|
24
47
|
- - "~>"
|
25
48
|
- !ruby/object:Gem::Version
|
26
|
-
version: 5.0
|
49
|
+
version: '5.0'
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: 5.0.0
|
27
53
|
- !ruby/object:Gem::Dependency
|
28
54
|
name: arel-extensions
|
29
55
|
requirement: !ruby/object:Gem::Requirement
|
30
56
|
requirements:
|
57
|
+
- - "~>"
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '1.0'
|
31
60
|
- - ">="
|
32
61
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
62
|
+
version: 1.0.0
|
34
63
|
type: :runtime
|
35
64
|
prerelease: false
|
36
65
|
version_requirements: !ruby/object:Gem::Requirement
|
37
66
|
requirements:
|
67
|
+
- - "~>"
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '1.0'
|
38
70
|
- - ">="
|
39
71
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
72
|
+
version: 1.0.0
|
41
73
|
- !ruby/object:Gem::Dependency
|
42
74
|
name: pg
|
43
75
|
requirement: !ruby/object:Gem::Requirement
|
44
76
|
requirements:
|
77
|
+
- - "~>"
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0.18'
|
45
80
|
- - ">="
|
46
81
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
82
|
+
version: 0.18.4
|
48
83
|
type: :development
|
49
84
|
prerelease: false
|
50
85
|
version_requirements: !ruby/object:Gem::Requirement
|
51
86
|
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0.18'
|
52
90
|
- - ">="
|
53
91
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
92
|
+
version: 0.18.4
|
55
93
|
- !ruby/object:Gem::Dependency
|
56
94
|
name: bundler
|
57
95
|
requirement: !ruby/object:Gem::Requirement
|
58
96
|
requirements:
|
97
|
+
- - "~>"
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '1.11'
|
59
100
|
- - ">="
|
60
101
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
102
|
+
version: 1.11.2
|
62
103
|
type: :development
|
63
104
|
prerelease: false
|
64
105
|
version_requirements: !ruby/object:Gem::Requirement
|
65
106
|
requirements:
|
107
|
+
- - "~>"
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '1.11'
|
66
110
|
- - ">="
|
67
111
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
112
|
+
version: 1.11.2
|
69
113
|
- !ruby/object:Gem::Dependency
|
70
114
|
name: rake
|
71
115
|
requirement: !ruby/object:Gem::Requirement
|
@@ -126,30 +170,30 @@ dependencies:
|
|
126
170
|
name: railties
|
127
171
|
requirement: !ruby/object:Gem::Requirement
|
128
172
|
requirements:
|
129
|
-
- - "
|
173
|
+
- - ">="
|
130
174
|
- !ruby/object:Gem::Version
|
131
|
-
version: 5.0.0
|
175
|
+
version: 5.0.0
|
132
176
|
type: :development
|
133
177
|
prerelease: false
|
134
178
|
version_requirements: !ruby/object:Gem::Requirement
|
135
179
|
requirements:
|
136
|
-
- - "
|
180
|
+
- - ">="
|
137
181
|
- !ruby/object:Gem::Version
|
138
|
-
version: 5.0.0
|
182
|
+
version: 5.0.0
|
139
183
|
- !ruby/object:Gem::Dependency
|
140
184
|
name: factory_girl_rails
|
141
185
|
requirement: !ruby/object:Gem::Requirement
|
142
186
|
requirements:
|
143
|
-
- - "
|
187
|
+
- - ">="
|
144
188
|
- !ruby/object:Gem::Version
|
145
|
-
version: 4.
|
189
|
+
version: 4.7.0
|
146
190
|
type: :development
|
147
191
|
prerelease: false
|
148
192
|
version_requirements: !ruby/object:Gem::Requirement
|
149
193
|
requirements:
|
150
|
-
- - "
|
194
|
+
- - ">="
|
151
195
|
- !ruby/object:Gem::Version
|
152
|
-
version: 4.
|
196
|
+
version: 4.7.0
|
153
197
|
- !ruby/object:Gem::Dependency
|
154
198
|
name: faker
|
155
199
|
requirement: !ruby/object:Gem::Requirement
|
@@ -193,9 +237,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
193
237
|
version: '0'
|
194
238
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
195
239
|
requirements:
|
196
|
-
- - "
|
240
|
+
- - ">="
|
197
241
|
- !ruby/object:Gem::Version
|
198
|
-
version:
|
242
|
+
version: '0'
|
199
243
|
requirements: []
|
200
244
|
rubyforge_project:
|
201
245
|
rubygems_version: 2.5.1
|