search_cop 1.0.0 → 1.0.1
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/CHANGELOG.md +37 -0
 - data/MIGRATION.md +21 -1
 - data/README.md +29 -33
 - data/lib/search_cop/version.rb +1 -1
 - data/lib/search_cop.rb +3 -5
 - metadata +3 -2
 
    
        data/CHANGELOG.md
    ADDED
    
    | 
         @@ -0,0 +1,37 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
             
     | 
| 
      
 2 
     | 
    
         
            +
            # Changelog
         
     | 
| 
      
 3 
     | 
    
         
            +
             
     | 
| 
      
 4 
     | 
    
         
            +
            Version 1.0.1:
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
            * Inheritance fix
         
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
      
 8 
     | 
    
         
            +
            Version 1.0.0:
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
            * Project name changed to SearchCop
         
     | 
| 
      
 11 
     | 
    
         
            +
            * Scope support added
         
     | 
| 
      
 12 
     | 
    
         
            +
            * Multiple DSL changes
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
      
 14 
     | 
    
         
            +
            Version 0.0.5:
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
            * Supporting :default => false
         
     | 
| 
      
 17 
     | 
    
         
            +
            * Datetime/Date greater operator fix
         
     | 
| 
      
 18 
     | 
    
         
            +
            * Use reflection to find associated models
         
     | 
| 
      
 19 
     | 
    
         
            +
            * Providing reflection
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
            Version 0.0.4:
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
      
 23 
     | 
    
         
            +
            * Fixed date attributes
         
     | 
| 
      
 24 
     | 
    
         
            +
            * Fail softly for mixed datatype attributes
         
     | 
| 
      
 25 
     | 
    
         
            +
            * Support custom table, class and alias names via attr_searchable_alias
         
     | 
| 
      
 26 
     | 
    
         
            +
             
     | 
| 
      
 27 
     | 
    
         
            +
            Version 0.0.3:
         
     | 
| 
      
 28 
     | 
    
         
            +
             
     | 
| 
      
 29 
     | 
    
         
            +
            * belongs_to association fixes
         
     | 
| 
      
 30 
     | 
    
         
            +
             
     | 
| 
      
 31 
     | 
    
         
            +
            Version 0.0.2:
         
     | 
| 
      
 32 
     | 
    
         
            +
             
     | 
| 
      
 33 
     | 
    
         
            +
            * Arel abstraction layer added
         
     | 
| 
      
 34 
     | 
    
         
            +
            * count() queries resulting in "Cannot visit AttrSearchableGrammar::Nodes..." fixed
         
     | 
| 
      
 35 
     | 
    
         
            +
            * Better error messages
         
     | 
| 
      
 36 
     | 
    
         
            +
            * Model#unsafe_search added
         
     | 
| 
      
 37 
     | 
    
         
            +
             
     | 
    
        data/MIGRATION.md
    CHANGED
    
    | 
         @@ -6,6 +6,26 @@ to change its DSL and name, as no `attr_searchable` method is present anymore. 
     | 
|
| 
       6 
6 
     | 
    
         
             
            The new DSL is cleaner and more concise. Morever, the migration process is
         
     | 
| 
       7 
7 
     | 
    
         
             
            simple.
         
     | 
| 
       8 
8 
     | 
    
         | 
| 
      
 9 
     | 
    
         
            +
            ## Installation
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
            Change
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
                gem 'attr_searchable'
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
            to
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
                gem 'search_cop'
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
      
 19 
     | 
    
         
            +
            And then execute:
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
                $ bundle
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
      
 23 
     | 
    
         
            +
            Or install it yourself as:
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
                $ gem install search_cop
         
     | 
| 
      
 26 
     | 
    
         
            +
             
     | 
| 
      
 27 
     | 
    
         
            +
            ## General DSL
         
     | 
| 
      
 28 
     | 
    
         
            +
             
     | 
| 
       9 
29 
     | 
    
         
             
            AttrSearchable:
         
     | 
| 
       10 
30 
     | 
    
         | 
| 
       11 
31 
     | 
    
         
             
            ```ruby
         
     | 
| 
         @@ -44,7 +64,7 @@ class Book < ActiveRecord::Base 
     | 
|
| 
       44 
64 
     | 
    
         
             
            end
         
     | 
| 
       45 
65 
     | 
    
         
             
            ```
         
     | 
| 
       46 
66 
     | 
    
         | 
| 
       47 
     | 
    
         
            -
             
     | 
| 
      
 67 
     | 
    
         
            +
            ## Reflection
         
     | 
| 
       48 
68 
     | 
    
         | 
| 
       49 
69 
     | 
    
         
             
            AttrSearchable:
         
     | 
| 
       50 
70 
     | 
    
         | 
    
        data/README.md
    CHANGED
    
    | 
         @@ -42,7 +42,7 @@ As the set of features of AttrSearchable grew and grew, it has been neccessary 
     | 
|
| 
       42 
42 
     | 
    
         
             
            to change its DSL and name, as no `attr_searchable` method is present anymore.
         
     | 
| 
       43 
43 
     | 
    
         
             
            The new DSL is cleaner and more concise. Morever, the migration process is
         
     | 
| 
       44 
44 
     | 
    
         
             
            simple. Please take a look into the migration guide
         
     | 
| 
       45 
     | 
    
         
            -
            [MIGRATION.md](https://github.com/mrkamel/search_cop/MIGRATION.md)
         
     | 
| 
      
 45 
     | 
    
         
            +
            [MIGRATION.md](https://github.com/mrkamel/search_cop/blob/master/MIGRATION.md)
         
     | 
| 
       46 
46 
     | 
    
         | 
| 
       47 
47 
     | 
    
         
             
            ## Installation
         
     | 
| 
       48 
48 
     | 
    
         | 
| 
         @@ -79,6 +79,22 @@ class Book < ActiveRecord::Base 
     | 
|
| 
       79 
79 
     | 
    
         
             
            end
         
     | 
| 
       80 
80 
     | 
    
         
             
            ```
         
     | 
| 
       81 
81 
     | 
    
         | 
| 
      
 82 
     | 
    
         
            +
            You can of course as well specify multiple `search_scope` blocks as you like:
         
     | 
| 
      
 83 
     | 
    
         
            +
             
     | 
| 
      
 84 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 85 
     | 
    
         
            +
            search_scope :admin_search do
         
     | 
| 
      
 86 
     | 
    
         
            +
              attributes :title, :description, :stock, :price, :created_at, :available
         
     | 
| 
      
 87 
     | 
    
         
            +
             
     | 
| 
      
 88 
     | 
    
         
            +
              # ...
         
     | 
| 
      
 89 
     | 
    
         
            +
            end
         
     | 
| 
      
 90 
     | 
    
         
            +
             
     | 
| 
      
 91 
     | 
    
         
            +
            search_scope :user_search do
         
     | 
| 
      
 92 
     | 
    
         
            +
              attributes :title, :description
         
     | 
| 
      
 93 
     | 
    
         
            +
             
     | 
| 
      
 94 
     | 
    
         
            +
              # ...
         
     | 
| 
      
 95 
     | 
    
         
            +
            end
         
     | 
| 
      
 96 
     | 
    
         
            +
            ```
         
     | 
| 
      
 97 
     | 
    
         
            +
             
     | 
| 
       82 
98 
     | 
    
         
             
            ## How does it work
         
     | 
| 
       83 
99 
     | 
    
         | 
| 
       84 
100 
     | 
    
         
             
            SearchCop parses the query and maps it to an SQL Query using Arel.
         
     | 
| 
         @@ -226,6 +242,13 @@ one of the easiest ways is: 
     | 
|
| 
       226 
242 
     | 
    
         
             
            ActiveRecord::Base.connection.execute "CREATE INDEX fulltext_index_books_on_title ON books USING GIN(to_tsvector('simple', title))"
         
     | 
| 
       227 
243 
     | 
    
         
             
            ```
         
     | 
| 
       228 
244 
     | 
    
         | 
| 
      
 245 
     | 
    
         
            +
            Moreover, for PostgreSQL you should change the schema format in
         
     | 
| 
      
 246 
     | 
    
         
            +
            `config/application.rb`:
         
     | 
| 
      
 247 
     | 
    
         
            +
             
     | 
| 
      
 248 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 249 
     | 
    
         
            +
            config.active_record.schema_format = :sql
         
     | 
| 
      
 250 
     | 
    
         
            +
            ```
         
     | 
| 
      
 251 
     | 
    
         
            +
             
     | 
| 
       229 
252 
     | 
    
         
             
            Regarding compound indices for PostgreSQL, use:
         
     | 
| 
       230 
253 
     | 
    
         | 
| 
       231 
254 
     | 
    
         
             
            ```ruby
         
     | 
| 
         @@ -488,6 +511,11 @@ Product.search_reflection(:search).default_attributes 
     | 
|
| 
       488 
511 
     | 
    
         
             
            # ...
         
     | 
| 
       489 
512 
     | 
    
         
             
            ```
         
     | 
| 
       490 
513 
     | 
    
         | 
| 
      
 514 
     | 
    
         
            +
            ## Semantic Versioning
         
     | 
| 
      
 515 
     | 
    
         
            +
             
     | 
| 
      
 516 
     | 
    
         
            +
            Starting with version 1.0.0, SearchCop uses Semantic Versioning:
         
     | 
| 
      
 517 
     | 
    
         
            +
            [SemVer](http://semver.org/)
         
     | 
| 
      
 518 
     | 
    
         
            +
             
     | 
| 
       491 
519 
     | 
    
         
             
            ## Contributing
         
     | 
| 
       492 
520 
     | 
    
         | 
| 
       493 
521 
     | 
    
         
             
            1. Fork it
         
     | 
| 
         @@ -496,35 +524,3 @@ Product.search_reflection(:search).default_attributes 
     | 
|
| 
       496 
524 
     | 
    
         
             
            4. Push to the branch (`git push origin my-new-feature`)
         
     | 
| 
       497 
525 
     | 
    
         
             
            5. Create new Pull Request
         
     | 
| 
       498 
526 
     | 
    
         | 
| 
       499 
     | 
    
         
            -
            ## Changelog
         
     | 
| 
       500 
     | 
    
         
            -
             
     | 
| 
       501 
     | 
    
         
            -
            Version 1.0.0:
         
     | 
| 
       502 
     | 
    
         
            -
             
     | 
| 
       503 
     | 
    
         
            -
            * Project name changed to SearchCop
         
     | 
| 
       504 
     | 
    
         
            -
            * Scope support added
         
     | 
| 
       505 
     | 
    
         
            -
            * Multiple DSL changes
         
     | 
| 
       506 
     | 
    
         
            -
             
     | 
| 
       507 
     | 
    
         
            -
            Version 0.0.5:
         
     | 
| 
       508 
     | 
    
         
            -
             
     | 
| 
       509 
     | 
    
         
            -
            * Supporting :default => false
         
     | 
| 
       510 
     | 
    
         
            -
            * Datetime/Date greater operator fix
         
     | 
| 
       511 
     | 
    
         
            -
            * Use reflection to find associated models
         
     | 
| 
       512 
     | 
    
         
            -
            * Providing reflection
         
     | 
| 
       513 
     | 
    
         
            -
             
     | 
| 
       514 
     | 
    
         
            -
            Version 0.0.4:
         
     | 
| 
       515 
     | 
    
         
            -
             
     | 
| 
       516 
     | 
    
         
            -
            * Fixed date attributes
         
     | 
| 
       517 
     | 
    
         
            -
            * Fail softly for mixed datatype attributes
         
     | 
| 
       518 
     | 
    
         
            -
            * Support custom table, class and alias names via attr_searchable_alias
         
     | 
| 
       519 
     | 
    
         
            -
             
     | 
| 
       520 
     | 
    
         
            -
            Version 0.0.3:
         
     | 
| 
       521 
     | 
    
         
            -
             
     | 
| 
       522 
     | 
    
         
            -
            * belongs_to association fixes
         
     | 
| 
       523 
     | 
    
         
            -
             
     | 
| 
       524 
     | 
    
         
            -
            Version 0.0.2:
         
     | 
| 
       525 
     | 
    
         
            -
             
     | 
| 
       526 
     | 
    
         
            -
            * Arel abstraction layer added
         
     | 
| 
       527 
     | 
    
         
            -
            * count() queries resulting in "Cannot visit AttrSearchableGrammar::Nodes..." fixed
         
     | 
| 
       528 
     | 
    
         
            -
            * Better error messages
         
     | 
| 
       529 
     | 
    
         
            -
            * Model#unsafe_search added
         
     | 
| 
       530 
     | 
    
         
            -
             
     | 
    
        data/lib/search_cop/version.rb
    CHANGED
    
    
    
        data/lib/search_cop.rb
    CHANGED
    
    | 
         @@ -32,16 +32,14 @@ module SearchCop 
     | 
|
| 
       32 
32 
     | 
    
         | 
| 
       33 
33 
     | 
    
         
             
                base.class_attribute :search_scopes
         
     | 
| 
       34 
34 
     | 
    
         
             
                base.search_scopes = {}
         
     | 
| 
       35 
     | 
    
         
            -
             
     | 
| 
       36 
     | 
    
         
            -
                base.search_scopes[:search] = SearchScope.new(:search, base)
         
     | 
| 
       37 
35 
     | 
    
         
             
              end
         
     | 
| 
       38 
36 
     | 
    
         | 
| 
       39 
37 
     | 
    
         
             
              module ClassMethods
         
     | 
| 
       40 
38 
     | 
    
         
             
                def search_scope(name, &block)
         
     | 
| 
       41 
     | 
    
         
            -
                   
     | 
| 
       42 
     | 
    
         
            -
                  search_scope.instance_exec(&block)
         
     | 
| 
      
 39 
     | 
    
         
            +
                  self.search_scopes = search_scopes.dup
         
     | 
| 
       43 
40 
     | 
    
         | 
| 
       44 
     | 
    
         
            -
                  search_scopes[name] =  
     | 
| 
      
 41 
     | 
    
         
            +
                  search_scopes[name] = SearchScope.new(name, self)
         
     | 
| 
      
 42 
     | 
    
         
            +
                  search_scopes[name].instance_exec(&block)
         
     | 
| 
       45 
43 
     | 
    
         | 
| 
       46 
44 
     | 
    
         
             
                  self.class.send(:define_method, name) { |query| search_cop query, name }
         
     | 
| 
       47 
45 
     | 
    
         
             
                  self.class.send(:define_method, "unsafe_#{name}") { |query| unsafe_search_cop query, name }
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: search_cop
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 1.0. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 1.0.1
         
     | 
| 
       5 
5 
     | 
    
         
             
              prerelease: 
         
     | 
| 
       6 
6 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       7 
7 
     | 
    
         
             
            authors:
         
     | 
| 
         @@ -9,7 +9,7 @@ authors: 
     | 
|
| 
       9 
9 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       10 
10 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       11 
11 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       12 
     | 
    
         
            -
            date: 2014- 
     | 
| 
      
 12 
     | 
    
         
            +
            date: 2014-08-19 00:00:00.000000000 Z
         
     | 
| 
       13 
13 
     | 
    
         
             
            dependencies:
         
     | 
| 
       14 
14 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       15 
15 
     | 
    
         
             
              name: treetop
         
     | 
| 
         @@ -133,6 +133,7 @@ files: 
     | 
|
| 
       133 
133 
     | 
    
         
             
            - .gitignore
         
     | 
| 
       134 
134 
     | 
    
         
             
            - .travis.yml
         
     | 
| 
       135 
135 
     | 
    
         
             
            - Appraisals
         
     | 
| 
      
 136 
     | 
    
         
            +
            - CHANGELOG.md
         
     | 
| 
       136 
137 
     | 
    
         
             
            - Gemfile
         
     | 
| 
       137 
138 
     | 
    
         
             
            - LICENSE.txt
         
     | 
| 
       138 
139 
     | 
    
         
             
            - MIGRATION.md
         
     |