blind_index 2.1.1 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +2 -2
- data/lib/blind_index.rb +5 -1
- data/lib/blind_index/extensions.rb +33 -14
- data/lib/blind_index/version.rb +1 -1
- metadata +2 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 80c561a0a96707de1176ae314d4d884e03390de9b8c4e23049d3649d7576937e
         | 
| 4 | 
            +
              data.tar.gz: ea819c68b4d1a44c492799225d3250a86186cca1a355a3ab2e65a02069ae4062
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 44835258443127734b6940287e1768935884c86b53d90bb5c39a9a5db372b937649f81e5a6f16d9e4605cb78b19824759b019461491176cb4b2e0bfd1330858d
         | 
| 7 | 
            +
              data.tar.gz: ddeeb0f625335d49e86ab0a5ff2350a7ae8c5b74ffd0322d7504763818b05ee6c648ea0d85b395c2f197266adfcb18015b37e556d6cbee04aea32f943d0123cd
         | 
    
        data/CHANGELOG.md
    CHANGED
    
    
    
        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. | 
| 299 | 
            +
            User.select { |u| u.email.include?("value") }
         | 
| 300 300 | 
             
            ```
         | 
| 301 301 |  | 
| 302 302 | 
             
            For `ILIKE`, use:
         | 
| 303 303 |  | 
| 304 304 | 
             
            ```ruby
         | 
| 305 | 
            -
            User. | 
| 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):
         | 
    
        data/lib/blind_index.rb
    CHANGED
    
    | @@ -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. | 
| 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 | 
            -
                   | 
| 5 | 
            -
                     | 
| 6 | 
            -
             | 
| 7 | 
            -
                       | 
| 8 | 
            -
                         | 
| 9 | 
            -
                           | 
| 10 | 
            -
             | 
| 11 | 
            -
                             | 
| 12 | 
            -
                              value. | 
| 13 | 
            -
             | 
| 14 | 
            -
                               | 
| 15 | 
            -
             | 
| 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 >=  | 
| 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]
         | 
    
        data/lib/blind_index/version.rb
    CHANGED
    
    
    
        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. | 
| 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 | 
| 11 | 
            +
            date: 2020-09-08 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: activesupport
         |