dusen 0.5.3 → 0.6.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.
- data/README.md +3 -0
- data/lib/dusen/active_record/base_ext.rb +12 -2
- data/lib/dusen/version.rb +1 -1
- data/spec/rails-3.0/Gemfile.lock +1 -1
- data/spec/rails-3.2/Gemfile.lock +1 -1
- data/spec/shared/spec/dusen/active_record/base_ext_spec.rb +36 -0
- metadata +69 -45
- checksums.yaml +0 -15
    
        data/README.md
    CHANGED
    
    | @@ -81,6 +81,9 @@ that looks roughly like the following: | |
| 81 81 | 
             
                  contacts.email LIKE "%market ave%"  OR 
         | 
| 82 82 | 
             
                  contacts.email LIKE "%market ave%" )
         | 
| 83 83 |  | 
| 84 | 
            +
            You can also use `where_like` to find all the records *not* matching some phrases, using the `:negate` option:
         | 
| 85 | 
            +
             | 
| 86 | 
            +
                Contact.where_like({ :name => 'foo' }, { :negate => true })
         | 
| 84 87 |  | 
| 85 88 | 
             
            Processing queries for qualified fields
         | 
| 86 89 | 
             
            ---------------------------------------
         | 
| @@ -88,14 +88,24 @@ module Dusen | |
| 88 88 |  | 
| 89 89 | 
             
                    end
         | 
| 90 90 |  | 
| 91 | 
            -
                    def where_like(conditions)
         | 
| 91 | 
            +
                    def where_like(conditions, options = {})
         | 
| 92 92 | 
             
                      scope = self
         | 
| 93 | 
            +
                      if options[:negate]
         | 
| 94 | 
            +
                        match_operator = 'NOT LIKE'
         | 
| 95 | 
            +
                        join_operator = 'AND'
         | 
| 96 | 
            +
                      else
         | 
| 97 | 
            +
                        match_operator = 'LIKE'
         | 
| 98 | 
            +
                        join_operator = 'OR'
         | 
| 99 | 
            +
                      end
         | 
| 100 | 
            +
             | 
| 93 101 | 
             
                      conditions.each do |field_or_fields, query|
         | 
| 94 102 | 
             
                        fields = Array(field_or_fields).collect do |field|
         | 
| 95 103 | 
             
                          Util.qualify_column_name(scope, field)
         | 
| 96 104 | 
             
                        end
         | 
| 97 105 | 
             
                        Array.wrap(query).each do |phrase|
         | 
| 98 | 
            -
                          phrase_with_placeholders = fields.collect { |field| | 
| 106 | 
            +
                          phrase_with_placeholders = fields.collect { |field|
         | 
| 107 | 
            +
                            "#{field} #{match_operator} ?"
         | 
| 108 | 
            +
                          }.join(" #{join_operator} ")
         | 
| 99 109 | 
             
                          like_expression = Dusen::Util.like_expression(phrase)
         | 
| 100 110 | 
             
                          bindings = [like_expression] * fields.size
         | 
| 101 111 | 
             
                          conditions = [ phrase_with_placeholders, *bindings ]
         | 
    
        data/lib/dusen/version.rb
    CHANGED
    
    
    
        data/spec/rails-3.0/Gemfile.lock
    CHANGED
    
    
    
        data/spec/rails-3.2/Gemfile.lock
    CHANGED
    
    
| @@ -181,6 +181,42 @@ shared_examples_for 'model with search syntax' do | |
| 181 181 | 
             
                end
         | 
| 182 182 |  | 
| 183 183 | 
             
              end
         | 
| 184 | 
            +
              
         | 
| 185 | 
            +
              describe '.where_like' do
         | 
| 186 | 
            +
             | 
| 187 | 
            +
                it 'matches a record if a word appears in any of the given columns' do
         | 
| 188 | 
            +
                  match1 = subject.create!(:name => 'word', :city => 'XXXX')
         | 
| 189 | 
            +
                  match2 = subject.create!(:name => 'XXXX', :city => 'word')
         | 
| 190 | 
            +
                  no_match = subject.create!(:name => 'XXXX', :city => 'XXXX')
         | 
| 191 | 
            +
                  subject.where_like([:name, :city] => 'word').to_a.should =~ [match1, match2]
         | 
| 192 | 
            +
                end
         | 
| 193 | 
            +
                
         | 
| 194 | 
            +
                it 'matches a record if it contains all the given words' do
         | 
| 195 | 
            +
                  match1 = subject.create!(:city => 'word1 word2')
         | 
| 196 | 
            +
                  match2 = subject.create!(:city => 'word2 word1')
         | 
| 197 | 
            +
                  no_match = subject.create!(:city => 'word1')
         | 
| 198 | 
            +
                  subject.where_like(:city => ['word1', 'word2']).to_a.should =~ [match1, match2]
         | 
| 199 | 
            +
                end
         | 
| 200 | 
            +
             | 
| 201 | 
            +
                describe 'with :negate option' do
         | 
| 202 | 
            +
             | 
| 203 | 
            +
                  it 'rejects a record if a word appears in any of the given columns' do
         | 
| 204 | 
            +
                    no_match1 = subject.create!(:name => 'word', :city => 'XXXX')
         | 
| 205 | 
            +
                    no_match2 = subject.create!(:name => 'XXXX', :city => 'word')
         | 
| 206 | 
            +
                    match = subject.create!(:name => 'XXXX', :city => 'XXXX')
         | 
| 207 | 
            +
                    subject.where_like({ [:name, :city] => 'word' }, :negate => true).to_a.should =~ [match]
         | 
| 208 | 
            +
                  end
         | 
| 209 | 
            +
             | 
| 210 | 
            +
                  it 'rejects a record if it matches at least one of the given words' do
         | 
| 211 | 
            +
                    no_match1 = subject.create!(:city => 'word1')
         | 
| 212 | 
            +
                    no_match2 = subject.create!(:city => 'word2')
         | 
| 213 | 
            +
                    match = subject.create!(:city => 'word3')
         | 
| 214 | 
            +
                    subject.where_like({ :city => ['word1', 'word2'] }, :negate => true).to_a.should =~ [match]
         | 
| 215 | 
            +
                  end
         | 
| 216 | 
            +
             | 
| 217 | 
            +
                end
         | 
| 218 | 
            +
                
         | 
| 219 | 
            +
              end
         | 
| 184 220 |  | 
| 185 221 | 
             
            end
         | 
| 186 222 |  | 
    
        metadata
    CHANGED
    
    | @@ -1,49 +1,62 @@ | |
| 1 | 
            -
            --- !ruby/object:Gem::Specification
         | 
| 1 | 
            +
            --- !ruby/object:Gem::Specification 
         | 
| 2 2 | 
             
            name: dusen
         | 
| 3 | 
            -
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
               | 
| 3 | 
            +
            version: !ruby/object:Gem::Version 
         | 
| 4 | 
            +
              hash: 7
         | 
| 5 | 
            +
              prerelease: 
         | 
| 6 | 
            +
              segments: 
         | 
| 7 | 
            +
              - 0
         | 
| 8 | 
            +
              - 6
         | 
| 9 | 
            +
              - 0
         | 
| 10 | 
            +
              version: 0.6.0
         | 
| 5 11 | 
             
            platform: ruby
         | 
| 6 | 
            -
            authors:
         | 
| 12 | 
            +
            authors: 
         | 
| 7 13 | 
             
            - Henning Koch
         | 
| 8 14 | 
             
            autorequire: 
         | 
| 9 15 | 
             
            bindir: bin
         | 
| 10 16 | 
             
            cert_chain: []
         | 
| 11 | 
            -
             | 
| 12 | 
            -
             | 
| 13 | 
            -
             | 
| 17 | 
            +
             | 
| 18 | 
            +
            date: 2015-06-14 00:00:00 Z
         | 
| 19 | 
            +
            dependencies: 
         | 
| 20 | 
            +
            - !ruby/object:Gem::Dependency 
         | 
| 14 21 | 
             
              name: activerecord
         | 
| 15 | 
            -
              requirement: !ruby/object:Gem::Requirement
         | 
| 16 | 
            -
                requirements:
         | 
| 17 | 
            -
                - - ! '>='
         | 
| 18 | 
            -
                  - !ruby/object:Gem::Version
         | 
| 19 | 
            -
                    version: '3.0'
         | 
| 20 | 
            -
              type: :runtime
         | 
| 21 22 | 
             
              prerelease: false
         | 
| 22 | 
            -
               | 
| 23 | 
            -
                 | 
| 24 | 
            -
                 | 
| 25 | 
            -
             | 
| 26 | 
            -
             | 
| 27 | 
            -
             | 
| 28 | 
            -
             | 
| 29 | 
            -
             | 
| 30 | 
            -
             | 
| 31 | 
            -
             | 
| 32 | 
            -
                  - !ruby/object:Gem::Version
         | 
| 33 | 
            -
                    version: 0.2.5
         | 
| 23 | 
            +
              requirement: &id001 !ruby/object:Gem::Requirement 
         | 
| 24 | 
            +
                none: false
         | 
| 25 | 
            +
                requirements: 
         | 
| 26 | 
            +
                - - ">="
         | 
| 27 | 
            +
                  - !ruby/object:Gem::Version 
         | 
| 28 | 
            +
                    hash: 7
         | 
| 29 | 
            +
                    segments: 
         | 
| 30 | 
            +
                    - 3
         | 
| 31 | 
            +
                    - 0
         | 
| 32 | 
            +
                    version: "3.0"
         | 
| 34 33 | 
             
              type: :runtime
         | 
| 34 | 
            +
              version_requirements: *id001
         | 
| 35 | 
            +
            - !ruby/object:Gem::Dependency 
         | 
| 36 | 
            +
              name: edge_rider
         | 
| 35 37 | 
             
              prerelease: false
         | 
| 36 | 
            -
               | 
| 37 | 
            -
                 | 
| 38 | 
            -
                 | 
| 39 | 
            -
             | 
| 38 | 
            +
              requirement: &id002 !ruby/object:Gem::Requirement 
         | 
| 39 | 
            +
                none: false
         | 
| 40 | 
            +
                requirements: 
         | 
| 41 | 
            +
                - - ">="
         | 
| 42 | 
            +
                  - !ruby/object:Gem::Version 
         | 
| 43 | 
            +
                    hash: 29
         | 
| 44 | 
            +
                    segments: 
         | 
| 45 | 
            +
                    - 0
         | 
| 46 | 
            +
                    - 2
         | 
| 47 | 
            +
                    - 5
         | 
| 40 48 | 
             
                    version: 0.2.5
         | 
| 49 | 
            +
              type: :runtime
         | 
| 50 | 
            +
              version_requirements: *id002
         | 
| 41 51 | 
             
            description: Comprehensive full text search for ActiveRecord and MySQL
         | 
| 42 52 | 
             
            email: henning.koch@makandra.de
         | 
| 43 53 | 
             
            executables: []
         | 
| 54 | 
            +
             | 
| 44 55 | 
             
            extensions: []
         | 
| 56 | 
            +
             | 
| 45 57 | 
             
            extra_rdoc_files: []
         | 
| 46 | 
            -
             | 
| 58 | 
            +
             | 
| 59 | 
            +
            files: 
         | 
| 47 60 | 
             
            - .gitignore
         | 
| 48 61 | 
             
            - .ruby-version
         | 
| 49 62 | 
             
            - .travis.yml
         | 
| @@ -125,27 +138,38 @@ files: | |
| 125 138 | 
             
            - spec/shared/spec/dusen/query_spec.rb
         | 
| 126 139 | 
             
            - spec/shared/spec/dusen/util_spec.rb
         | 
| 127 140 | 
             
            homepage: https://github.com/makandra/dusen
         | 
| 128 | 
            -
            licenses:
         | 
| 141 | 
            +
            licenses: 
         | 
| 129 142 | 
             
            - MIT
         | 
| 130 | 
            -
            metadata: {}
         | 
| 131 143 | 
             
            post_install_message: 
         | 
| 132 144 | 
             
            rdoc_options: []
         | 
| 133 | 
            -
             | 
| 145 | 
            +
             | 
| 146 | 
            +
            require_paths: 
         | 
| 134 147 | 
             
            - lib
         | 
| 135 | 
            -
            required_ruby_version: !ruby/object:Gem::Requirement
         | 
| 136 | 
            -
               | 
| 137 | 
            -
               | 
| 138 | 
            -
             | 
| 139 | 
            -
             | 
| 140 | 
            -
             | 
| 141 | 
            -
             | 
| 142 | 
            -
             | 
| 143 | 
            -
             | 
| 144 | 
            -
             | 
| 148 | 
            +
            required_ruby_version: !ruby/object:Gem::Requirement 
         | 
| 149 | 
            +
              none: false
         | 
| 150 | 
            +
              requirements: 
         | 
| 151 | 
            +
              - - ">="
         | 
| 152 | 
            +
                - !ruby/object:Gem::Version 
         | 
| 153 | 
            +
                  hash: 3
         | 
| 154 | 
            +
                  segments: 
         | 
| 155 | 
            +
                  - 0
         | 
| 156 | 
            +
                  version: "0"
         | 
| 157 | 
            +
            required_rubygems_version: !ruby/object:Gem::Requirement 
         | 
| 158 | 
            +
              none: false
         | 
| 159 | 
            +
              requirements: 
         | 
| 160 | 
            +
              - - ">="
         | 
| 161 | 
            +
                - !ruby/object:Gem::Version 
         | 
| 162 | 
            +
                  hash: 3
         | 
| 163 | 
            +
                  segments: 
         | 
| 164 | 
            +
                  - 0
         | 
| 165 | 
            +
                  version: "0"
         | 
| 145 166 | 
             
            requirements: []
         | 
| 167 | 
            +
             | 
| 146 168 | 
             
            rubyforge_project: 
         | 
| 147 | 
            -
            rubygems_version:  | 
| 169 | 
            +
            rubygems_version: 1.8.25
         | 
| 148 170 | 
             
            signing_key: 
         | 
| 149 | 
            -
            specification_version:  | 
| 171 | 
            +
            specification_version: 3
         | 
| 150 172 | 
             
            summary: Comprehensive full text search for ActiveRecord and MySQL
         | 
| 151 173 | 
             
            test_files: []
         | 
| 174 | 
            +
             | 
| 175 | 
            +
            has_rdoc: 
         | 
    
        checksums.yaml
    DELETED
    
    | @@ -1,15 +0,0 @@ | |
| 1 | 
            -
            ---
         | 
| 2 | 
            -
            !binary "U0hBMQ==":
         | 
| 3 | 
            -
              metadata.gz: !binary |-
         | 
| 4 | 
            -
                OWVjNGViYjQ5OGJlOWNjNzM5ZmMzMzBjZTYxODEyN2VjMWRiZTZlYQ==
         | 
| 5 | 
            -
              data.tar.gz: !binary |-
         | 
| 6 | 
            -
                OTQ2ODMzOTg0ZmZhYjg4NjYyMjMyOWNlZDVmZmYxOWU5ZThjYTE5Ng==
         | 
| 7 | 
            -
            SHA512:
         | 
| 8 | 
            -
              metadata.gz: !binary |-
         | 
| 9 | 
            -
                NmJjMzI3NDUzMjY1MzgwNDZjMzMxZDcwZmNkNWY5NWUyOWQyMWRkOTg1NTEy
         | 
| 10 | 
            -
                ZTljNjlhYmZlZWI2MDQyMGM1MmEzZTBlZTcyNzRmOTVlZDQxMDA0MDI1ZWEz
         | 
| 11 | 
            -
                ODAzMTAyYzgwMjI1Nzc0YThkMTVmMzE5YmI5NTRjYjg2NjYxMDI=
         | 
| 12 | 
            -
              data.tar.gz: !binary |-
         | 
| 13 | 
            -
                YTZjYTYzMDYxNDEzMDM4M2RlM2MyY2NmYTcxOWMzYjczYjY5ZjY3YmFkOTBj
         | 
| 14 | 
            -
                ZjYxMWJiOTY4OTE0OWI4ZjMxMzMzMjc0MTY4NWM5NzMwZDk0NzBkMmEwM2Vl
         | 
| 15 | 
            -
                NzA3ZmQyMTIxODVhNmJlMDk0ZWQ3ZTY3NDVjMDRiNDNkMTEzNjc=
         |