effective_resources 1.3.14 → 1.3.15

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
  SHA256:
3
- metadata.gz: b8f669acc7d9842e3a4f72fd492b031b168cd3a338b65f7e39048c5d904315ce
4
- data.tar.gz: 9c4063272dfb5a3a8c7ea72eda7593ec5d151a19ce0d884fcfa0713243668910
3
+ metadata.gz: c9401a04b558eb6438c84b7a4fefe259d37fc3deecf022aa95729a18fdc24511
4
+ data.tar.gz: 137da931f63327136a49d05ad14de51cd1b70f7d0878dc530978f9778d79da7e
5
5
  SHA512:
6
- metadata.gz: 6afe90060b1da85f845e90366e583459f983146d257b73dd2fcf07dd1b8640f2dc7c8c7ecfcc90734da3ecba792ab9f38449425f0e05047a175402dbcc7ff5a9
7
- data.tar.gz: ce169492089c7c33d24b0d72cfde11d00966370101d31502ebf5e403eb9115cc8cb3f499547e5ccecab2582ae8134aa243e874bff3aacf9af30dd347d0f38f36
6
+ metadata.gz: 4da7d55ebb3f63dff8f64a549cd6fc90331dcbf7e41b37c19dcf780390efd10e62f15db71175514e30344d60d448d3b9943bcfb165769ecfc4eb7d98c1976c08
7
+ data.tar.gz: 1301f38268a74ae5a159c0a63fa8af7f5b4ace3a157d10a45ebcf46abcec25eb0709519354a28394e2355b0507ba47c5ef5ffc7c22ce4062c70044a55151c040
@@ -27,7 +27,6 @@ module Effective
27
27
  case sql_type
28
28
  when :belongs_to
29
29
  relation
30
- .order(Arel.sql("#{is_null(sql_column)} ASC"))
31
30
  .order(order_by_associated_conditions(association, sort: sort, direction: direction, limit: limit))
32
31
  when :belongs_to_polymorphic
33
32
  relation
@@ -71,13 +70,17 @@ module Effective
71
70
  term = Effective::Attribute.new(sql_type, klass: (association.try(:klass) rescue nil) || klass).parse(value, name: name)
72
71
 
73
72
  # term == 'nil' rescue false is a Rails 4.1 fix, where you can't compare a TimeWithZone to 'nil'
74
- if (term == 'nil' rescue false) && ![:has_and_belongs_to_many, :has_many, :has_one, :belongs_to_polymorphic, :effective_roles].include?(sql_type)
73
+ if (term == 'nil' rescue false) && ![:has_and_belongs_to_many, :has_many, :has_one, :belongs_to, :belongs_to_polymorphic, :effective_roles].include?(sql_type)
75
74
  return relation.where(is_null(sql_column))
76
75
  end
77
76
 
78
77
  case sql_type
79
- when :belongs_to, :has_and_belongs_to_many, :has_many, :has_one
80
- relation.where(search_by_associated_conditions(association, term, fuzzy: fuzzy))
78
+ when :belongs_to
79
+ if term == 'nil'
80
+ relation.where(is_null(association.foreign_key))
81
+ else
82
+ relation.where(search_by_associated_conditions(association, term, fuzzy: fuzzy))
83
+ end
81
84
  when :belongs_to_polymorphic
82
85
  (type, id) = term.split('_')
83
86
 
@@ -89,6 +92,8 @@ module Effective
89
92
  id ||= Effective::Attribute.new(:integer).parse(term)
90
93
  relation.where("#{sql_column}_id = ? OR #{sql_column}_type = ?", id, (type || term))
91
94
  end
95
+ when :has_and_belongs_to_many, :has_many, :has_one
96
+ relation.where(search_by_associated_conditions(association, term, fuzzy: fuzzy))
92
97
  when :effective_addresses
93
98
  relation.where(id: Effective::Resource.new(association).search_any(value, fuzzy: fuzzy).pluck(:addressable_id))
94
99
  when :effective_obfuscation
@@ -160,6 +165,11 @@ module Effective
160
165
  return relation.where(klass.primary_key => value)
161
166
  end
162
167
 
168
+ # If the value is 3-something-like-this
169
+ if (values = value.to_s.split('-')).length > 0 && (maybe_id = values.first).present?
170
+ return relation.where(klass.primary_key => maybe_id) if (maybe_id.to_i.to_s == maybe_id)
171
+ end
172
+
163
173
  # Otherwise, we fall back to a string/text search of all columns
164
174
  columns = Array(columns || search_columns)
165
175
  fuzzy = true unless fuzzy == false
@@ -298,7 +308,7 @@ module Effective
298
308
  end
299
309
 
300
310
  def order_by_array_position(keys, field)
301
- keys = Array(keys).uniq.compact
311
+ keys = Array(keys).uniq.compact.presence || [0]
302
312
 
303
313
  if postgres?
304
314
  Arel.sql("array_position(ARRAY[#{keys.first(TARGET_KEYS_LIMIT).join(',')}]::text::int[], #{field}::int)")
@@ -1,3 +1,3 @@
1
1
  module EffectiveResources
2
- VERSION = '1.3.14'.freeze
2
+ VERSION = '1.3.15'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_resources
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.14
4
+ version: 1.3.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-08-15 00:00:00.000000000 Z
11
+ date: 2019-09-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails