blind_index 2.1.1 → 2.2.0

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: 030c05f4653c350dbbfc5dd2f39727e44819c286865b27a18ac10c6e94fca449
4
- data.tar.gz: f92d3e7d76a1b9ae65fe55bc1cf39e4a133dd633f2c620f0fa75dd0f35df8a55
3
+ metadata.gz: 80c561a0a96707de1176ae314d4d884e03390de9b8c4e23049d3649d7576937e
4
+ data.tar.gz: ea819c68b4d1a44c492799225d3250a86186cca1a355a3ab2e65a02069ae4062
5
5
  SHA512:
6
- metadata.gz: aa5d431804b50709280499845fd4609b0d576328c01a9be87f5d6cffeeb0a37d9fa10eba6a0f5fa33ccae83056bb939e25b85373839ba3d232f1488c88ce6d36
7
- data.tar.gz: ddec86434f1b6908763d454a7fa67507bbb0b98bf30c0038b4331dae26d314c58c4a9312b3db1ffff087aa8a3162e8e30cc4082c60f8aadccb688e78d80c4934
6
+ metadata.gz: 44835258443127734b6940287e1768935884c86b53d90bb5c39a9a5db372b937649f81e5a6f16d9e4605cb78b19824759b019461491176cb4b2e0bfd1330858d
7
+ data.tar.gz: ddeeb0f625335d49e86ab0a5ff2350a7ae8c5b74ffd0322d7504763818b05ee6c648ea0d85b395c2f197266adfcb18015b37e556d6cbee04aea32f943d0123cd
@@ -1,3 +1,7 @@
1
+ ## 2.2.0 (2020-09-07)
2
+
3
+ - Added support for `where` with table in Active Record 5.2+
4
+
1
5
  ## 2.1.1 (2020-08-14)
2
6
 
3
7
  - Fixed `version` option
data/README.md CHANGED
@@ -296,13 +296,13 @@ Unfortunately, blind indexes can’t be used for `LIKE`, `ILIKE`, or full-text s
296
296
  For `LIKE`, use:
297
297
 
298
298
  ```ruby
299
- User.find { |u| u.email.include?("value") }
299
+ User.select { |u| u.email.include?("value") }
300
300
  ```
301
301
 
302
302
  For `ILIKE`, use:
303
303
 
304
304
  ```ruby
305
- User.find { |u| u.email =~ /value/i }
305
+ User.select { |u| u.email =~ /value/i }
306
306
  ```
307
307
 
308
308
  For full-text or fuzzy searching, use a gem like [FuzzyMatch](https://github.com/seamusabshere/fuzzy_match):
@@ -141,9 +141,13 @@ ActiveSupport.on_load(:active_record) do
141
141
  ActiveRecord::TableMetadata.prepend(BlindIndex::Extensions::TableMetadata)
142
142
  ActiveRecord::DynamicMatchers::Method.prepend(BlindIndex::Extensions::DynamicMatchers)
143
143
 
144
- unless ActiveRecord::VERSION::STRING.start_with?("5.1.")
144
+ unless ActiveRecord::VERSION::STRING.to_f == 5.1
145
145
  ActiveRecord::Validations::UniquenessValidator.prepend(BlindIndex::Extensions::UniquenessValidator)
146
146
  end
147
+
148
+ if ActiveRecord::VERSION::STRING.to_f >= 5.2
149
+ ActiveRecord::PredicateBuilder.prepend(BlindIndex::Extensions::PredicateBuilder)
150
+ end
147
151
  end
148
152
 
149
153
  ActiveSupport.on_load(:mongoid) do
@@ -1,22 +1,24 @@
1
1
  module BlindIndex
2
2
  module Extensions
3
3
  module TableMetadata
4
- def resolve_column_aliases(hash)
5
- new_hash = super
6
- if has_blind_indexes?
7
- hash.each do |key, _|
8
- if key.respond_to?(:to_sym) && (bi = klass.blind_indexes[key.to_sym]) && !new_hash[key].is_a?(ActiveRecord::StatementCache::Substitute)
9
- value = new_hash.delete(key)
10
- new_hash[bi[:bidx_attribute]] =
11
- if value.is_a?(Array)
12
- value.map { |v| BlindIndex.generate_bidx(v, **bi) }
13
- else
14
- BlindIndex.generate_bidx(value, **bi)
15
- end
4
+ if ActiveRecord::VERSION::STRING.to_f < 5.2
5
+ def resolve_column_aliases(hash)
6
+ new_hash = super
7
+ if has_blind_indexes?
8
+ hash.each_key do |key|
9
+ if key.respond_to?(:to_sym) && (bi = klass.blind_indexes[key.to_sym]) && !new_hash[key].is_a?(ActiveRecord::StatementCache::Substitute)
10
+ value = new_hash.delete(key)
11
+ new_hash[bi[:bidx_attribute]] =
12
+ if value.is_a?(Array)
13
+ value.map { |v| BlindIndex.generate_bidx(v, **bi) }
14
+ else
15
+ BlindIndex.generate_bidx(value, **bi)
16
+ end
17
+ end
16
18
  end
17
19
  end
20
+ new_hash
18
21
  end
19
- new_hash
20
22
  end
21
23
 
22
24
  # memoize for performance
@@ -28,6 +30,23 @@ module BlindIndex
28
30
  end
29
31
  end
30
32
 
33
+ module PredicateBuilder
34
+ # https://github.com/rails/rails/commit/56f30962b84fc53b76001301fb830c1594fd377e
35
+ def build(attribute, value, *args)
36
+ if table.has_blind_indexes? && (bi = table.send(:klass).blind_indexes[attribute.name.to_sym]) && !value.is_a?(ActiveRecord::StatementCache::Substitute)
37
+ attribute = attribute.relation[bi[:bidx_attribute]]
38
+ value =
39
+ if value.is_a?(Array)
40
+ value.map { |v| BlindIndex.generate_bidx(v, **bi) }
41
+ else
42
+ BlindIndex.generate_bidx(value, **bi)
43
+ end
44
+ end
45
+
46
+ super(attribute, value, *args)
47
+ end
48
+ end
49
+
31
50
  module UniquenessValidator
32
51
  def validate_each(record, attribute, value)
33
52
  klass = record.class
@@ -38,7 +57,7 @@ module BlindIndex
38
57
  end
39
58
 
40
59
  # change attribute name here instead of validate_each for better error message
41
- if ActiveRecord::VERSION::STRING >= "5.2"
60
+ if ActiveRecord::VERSION::STRING.to_f >= 5.2
42
61
  def build_relation(klass, attribute, value)
43
62
  if klass.respond_to?(:blind_indexes) && (bi = klass.blind_indexes[attribute])
44
63
  attribute = bi[:bidx_attribute]
@@ -1,3 +1,3 @@
1
1
  module BlindIndex
2
- VERSION = "2.1.1"
2
+ VERSION = "2.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blind_index
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.1
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kane
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-08-14 00:00:00.000000000 Z
11
+ date: 2020-09-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport