activerecord-filter 1.0.2 → 5.0.0.beta1

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: 6972a66d47b1b0159da629d6176d8b778e3bf550
4
- data.tar.gz: ab9d9691554164cd7359adaa9213e16e816f6315
3
+ metadata.gz: 0ad1d6c4fde489d32e18e7a09fded1dc6f885733
4
+ data.tar.gz: 90ad1edbedee643cb629ceb2d6a65181f535fc7e
5
5
  SHA512:
6
- metadata.gz: 9cde58259c994ff059b9cdde7171f0fec6015d81925c0d76bf33d196990cb9d4bf8696ae04140c8f90ea1b52fe0dda17a2b36f6f83a83ada0dca05b4183df83e
7
- data.tar.gz: 6d2f65e8d9a0aac71bdde88bb230c97d0dc742978c30f74f46ccfba2a7b93424c820bf7998f0b933788dd59fbd2d9efb9da641f2954db93fbdad0ab3440d7f0e
6
+ metadata.gz: f5bda8ea3d34ad175787b16981fc9d9cd6048aa885e97b09e29714a1b3f1b20fe3d0786333e82f50eaeb9db901f48c13e8ea2ef4b0a16ea8cd5c83ba8fdaf5a7
7
+ data.tar.gz: f36d565425a76172ab801cc3c84540daebaf579241c92e84bb8154deb6a3e6dcc192c68d369f4d8a9e059935097c6ece203ea009a78a12f140a72cfb5dd5a735
@@ -15,7 +15,7 @@ class ActiveRecord::Base
15
15
  resource = all
16
16
  return resource unless filters
17
17
 
18
- if filters.is_a? Hash
18
+ if filters.is_a?(Hash) || filters.is_a?(ActionController::Parameters)
19
19
  filters.each do |key, value|
20
20
  if @filters[key]
21
21
  #TODO add test for this... not sure how rails does this lambda call,
@@ -54,13 +54,15 @@ class ActiveRecord::Base
54
54
  filter_for_text: :itself,
55
55
  filter_for_boolean: :itself,
56
56
  filter_for_string: :itself,
57
- filter_for_decimal: :to_f
57
+ filter_for_uuid: :itself,
58
+ filter_for_decimal: :to_f,
59
+ filter_for_float: :to_f
58
60
  }.each_pair do |method_name, send_method|
59
61
  define_method(method_name) do |column, value, options={}|
60
62
  table = options[:table_alias] ? arel_table.alias(options[:table_alias]) : arel_table
61
63
 
62
64
  case value
63
- when Hash
65
+ when Hash, ActionController::Parameters
64
66
  resource = all
65
67
  value.each_pair do |key, value|
66
68
  converted_value = value.try(:send, send_method)
@@ -87,7 +89,7 @@ class ActiveRecord::Base
87
89
  # end
88
90
 
89
91
  # TODO us above if to determin if SRID sent
90
- geometry_value = if value.is_a?(Hash)
92
+ geometry_value = if value.is_a?(Hash) || value.is_a?(ActionController::Parameters)
91
93
  Arel::Nodes::NamedFunction.new('ST_SetSRID', [Arel::Nodes::NamedFunction.new('ST_GeomFromGeoJSON', [Arel::Nodes.build_quoted(JSON.generate(value))]), 4326])
92
94
  elsif value[0,1] == "\x00" || value[0,1] == "\x01" || value[0,4] =~ /[0-9a-fA-F]{4}/
93
95
  Arel::Nodes::NamedFunction.new('ST_SetSRID', [Arel::Nodes::NamedFunction.new('ST_GeomFromEWKB', [Arel::Nodes.build_quoted(value)]), 4326])
@@ -142,7 +144,7 @@ class ActiveRecord::Base
142
144
  table = options[:table_alias] ? arel_table.alias(options[:table_alias]) : arel_table
143
145
 
144
146
  case value
145
- when Hash
147
+ when Hash, ActionController::Parameters
146
148
  resource = all
147
149
  value.each_pair do |key, value|
148
150
  resource = case key.to_sym
@@ -150,6 +152,10 @@ class ActiveRecord::Base
150
152
  resource.where(Arel::Nodes::Contains.new(table[column], Arel::Attributes::Array.new(Array(value))))
151
153
  when :overlaps
152
154
  resource.where(Arel::Nodes::Overlaps.new(table[column], Arel::Attributes::Array.new(Array(value))))
155
+ when :not_overlaps
156
+ resource.where.not(Arel::Nodes::Overlaps.new(table[column], Arel::Attributes::Array.new(Array(value))))
157
+ when :not_contains
158
+ resource.where.not(Arel::Nodes::Contains.new(table[column], Arel::Attributes::Array.new(Array(value))))
153
159
  else
154
160
  raise "Not Supported: #{key.to_sym}"
155
161
  end
@@ -158,9 +164,7 @@ class ActiveRecord::Base
158
164
  when Array
159
165
  where(Arel::Nodes::Contains.new(table[column], Arel::Attributes::Array.new(value)))
160
166
  else
161
- any_column = Arel::Nodes::NamedFunction.new('ANY', [table[column]])
162
- predicate = Arel::Nodes::Equality.new(Arel::Nodes.build_quoted(value), any_column)
163
- where(predicate)
167
+ where(Arel::Nodes::Contains.new(table[column], Arel::Attributes::Array.new([value])))
164
168
  end
165
169
  end
166
170
 
@@ -173,7 +177,7 @@ class ActiveRecord::Base
173
177
  end
174
178
 
175
179
  case value
176
- when Hash
180
+ when Hash, ActionController::Parameters
177
181
  resource = resource.joins(relation.name) if !resource.references?(relation.name)
178
182
  resource = resource.merge(relation.klass.filter(value, options))
179
183
  when Integer
@@ -193,7 +197,7 @@ class ActiveRecord::Base
193
197
  resource = all
194
198
 
195
199
  case value
196
- when Hash
200
+ when Hash, ActionController::Parameters
197
201
  if relation.options[:through]
198
202
  resource = resource.joins(relation.options[:through] => relation.source_reflection_name)
199
203
  else
@@ -235,7 +239,7 @@ class ActiveRecord::Base
235
239
  resource = resource.where(resource.arel_table[:"#{relation.foreign_key}"].not_eq(nil))
236
240
  when false, 'false'
237
241
  resource = resource.where(resource.arel_table[:"#{relation.foreign_key}"].eq(nil))
238
- when Hash
242
+ when Hash, ActionController::Parameters
239
243
  if relation.polymorphic?
240
244
  raise 'no :as' if !value[:as]
241
245
  v = value.dup
@@ -1,24 +1,24 @@
1
- module ActiveRecord::QueryMethods
2
-
3
- # # TODO: testme and rename to joins?
4
- # def joined?(assoc)
5
- # joined_assocs = joins_values.map{ |i| i.is_a?(Hash) ? i.keys : i.to_sym }.flatten
6
- # joined_assocs.include?(assoc)
7
- # end
8
- #
9
- # # TODO: testme and rename to includes?
10
- # def included?(assoc)
11
- # included_assocs = includes_values.map{ |i| i.is_a?(Hash) ? i.keys : i.to_sym }.flatten
12
- # included_assocs.include?(assoc)
13
- # end
14
-
15
- # TODO: testme and rename to
16
- def references?(assoc)
17
- references_assocs = references_values.map{ |i| i.is_a?(Hash) ? i.keys : i.to_sym }.flatten
18
- references_assocs.include?(assoc)
19
- end
20
-
21
- end
1
+ # module ActiveRecord::QueryMethods
2
+ #
3
+ # # # TODO: testme and rename to joins?
4
+ # # def joined?(assoc)
5
+ # # joined_assocs = joins_values.map{ |i| i.is_a?(Hash) ? i.keys : i.to_sym }.flatten
6
+ # # joined_assocs.include?(assoc)
7
+ # # end
8
+ # #
9
+ # # # TODO: testme and rename to includes?
10
+ # # def included?(assoc)
11
+ # # included_assocs = includes_values.map{ |i| i.is_a?(Hash) ? i.keys : i.to_sym }.flatten
12
+ # # included_assocs.include?(assoc)
13
+ # # end
14
+ #
15
+ # # TODO: testme and rename to
16
+ # def references?(assoc)
17
+ # references_assocs = references_values.map{ |i| i.is_a?(Hash) ? i.keys : i.to_sym }.flatten
18
+ # references_assocs.include?(assoc)
19
+ # end
20
+ #
21
+ # end
22
22
 
23
23
  module ActiveRecord::Querying
24
24
  # delegate :joined?, :to => :all
@@ -29,7 +29,7 @@ module Arel
29
29
  ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Array.new("ActiveRecord::Type::#{dt}".constantize.new)
30
30
  end
31
31
 
32
- collector << quote(type.type_cast_for_database(o.relation))
32
+ collector << quote(type.serialize(o.relation))
33
33
  end
34
34
 
35
35
  end
@@ -1,5 +1,5 @@
1
1
  module ActiveRecord
2
2
  module Filter
3
- VERSION = '1.0.2'
3
+ VERSION = '5.0.0.beta1'
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: 1.0.2
4
+ version: 5.0.0.beta1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jon Bracy
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-16 00:00:00.000000000 Z
11
+ date: 2016-01-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pg
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '4.0'
33
+ version: 5.0.0.beta1
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '4.0'
40
+ version: 5.0.0.beta1
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -172,12 +172,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
172
172
  version: '0'
173
173
  required_rubygems_version: !ruby/object:Gem::Requirement
174
174
  requirements:
175
- - - ">="
175
+ - - ">"
176
176
  - !ruby/object:Gem::Version
177
- version: '0'
177
+ version: 1.3.1
178
178
  requirements: []
179
179
  rubyforge_project:
180
- rubygems_version: 2.4.5
180
+ rubygems_version: 2.5.1
181
181
  signing_key:
182
182
  specification_version: 4
183
183
  summary: A safe way to accept user parameters and query against your ActiveRecord