activerecord-filter 5.0.0 → 5.0.0.1

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: 4fdf28c6e50c3f887b05980cf00e7070bab91b91
4
- data.tar.gz: 491ce24013f744189405c9a92845a7f275b7ca23
3
+ metadata.gz: d1fe442ec2d9469a50ef10c77bb05d728407be95
4
+ data.tar.gz: d6670cedb256f494a36d7af5ffa2a582398ffd16
5
5
  SHA512:
6
- metadata.gz: fa8bec5eb557ce931bd580d0a32e4cf014c734f22a32652d5778aa247220bf8dee24efa1af7db6ce44ef73134ecb8066d32bfed19a787fa844ed82d5e95033e7
7
- data.tar.gz: b9b9867c21937111b5770269dbe6b6327cd0eb626974c23f898e718d1eb6a6132ecdaabd0cfb2a836f374a161b4b25b4cb89a1dfe2d2f6ba6a0d107e3dc22c62
6
+ metadata.gz: c42f5aab8ec42ea638761946ba345e2b79900c426b8fec9d794cb2715c787ce3792db73229529656bdafe6e9141e4266dd05187be38bdd040582218638e49eb4
7
+ data.tar.gz: 459451d4a977fcf775047da9677ddf9011f88572436ac15d81f48044e6856ec0de832d32179a71a8f4d5783258f112053c3977739e230c9a7d5ca42a66ed4052
@@ -3,13 +3,6 @@ require 'arel/extensions'
3
3
  require 'action_controller/metal/strong_parameters'
4
4
 
5
5
  class ActiveRecord::UnkownFilterError < NoMethodError
6
- attr_reader :klass, :filter
7
-
8
- def initialize(klass, filter)
9
- @klass = klass
10
- @filter = filter.to_s
11
- super("unkown filter #{filter.inspect} for #{klass}.")
12
- end
13
6
  end
14
7
 
15
8
  module ActiveRecord::Filter
@@ -47,28 +40,15 @@ module ActiveRecord::Filter
47
40
 
48
41
  def filter_for(key, value, options={})
49
42
  column = columns_hash[key.to_s]
43
+
50
44
  if column && column.array
51
45
  all.filter_for_array(key, value, options)
52
46
  elsif column
53
47
  all.send("filter_for_#{column.type}", key, value, options)
48
+ elsif relation = reflect_on_association(key)
49
+ self.send("filter_for_#{relation.macro}", relation, value)
54
50
  else
55
- if relation = reflect_on_association(key)
56
- self.send("filter_for_#{relation.macro}", relation, value)
57
- else
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}"
61
- else
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)
70
- end
71
- end
51
+ raise ActiveRecord::UnkownFilterError.new("Unkown filter \"#{key}\" for #{self}.")
72
52
  end
73
53
  end
74
54
 
@@ -161,8 +141,10 @@ module ActiveRecord::Filter
161
141
  # # TODO support nil. Currently rails params encode nil as empty strings,
162
142
  # # and we can't tell which is desired, so do both
163
143
  # where(table[column].eq(value).or(table[column].eq(nil)))
164
- else
144
+ elsif value.respond_to?(send_method)
165
145
  where(table[column].eq(value.try(:send, send_method)))
146
+ else
147
+ raise ActiveRecord::UnkownFilterError.new("Unkown type for #{column}. (type #{value.class})")
166
148
  end
167
149
  end
168
150
  end
@@ -238,10 +220,12 @@ module ActiveRecord::Filter
238
220
  resource = all
239
221
 
240
222
  options = {}
241
- if resource.klass == relation.klass
223
+ if connection.class.name == 'ActiveRecord::ConnectionAdapters::SunstoneAPIAdapter'
224
+ options[:table_alias] = relation.name
225
+ elsif resource.klass == relation.klass
242
226
  options[:table_alias] = "#{relation.name}_#{relation.klass.table_name}"
243
227
  end
244
-
228
+
245
229
  if value.is_a?(Hash) || value.class.name == "ActionController::Parameters".freeze
246
230
  resource = resource.joins(relation.name) #if !resource.references?(relation.name)
247
231
  resource = resource.merge(relation.klass.filter(value, options))
@@ -1,5 +1,5 @@
1
1
  module ActiveRecord
2
2
  module Filter
3
- VERSION = '5.0.0'
3
+ VERSION = '5.0.0.1'
4
4
  end
5
5
  end
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.1
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-08-17 00:00:00.000000000 Z
11
+ date: 2016-09-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -242,7 +242,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
242
242
  version: '0'
243
243
  requirements: []
244
244
  rubyforge_project:
245
- rubygems_version: 2.5.1
245
+ rubygems_version: 2.6.4
246
246
  signing_key:
247
247
  specification_version: 4
248
248
  summary: A safe way to accept user parameters and query against your ActiveRecord