search_cop 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +18 -0
- data/.travis.yml +33 -0
- data/Appraisals +14 -0
- data/Gemfile +23 -0
- data/LICENSE.txt +22 -0
- data/MIGRATION.md +66 -0
- data/README.md +530 -0
- data/Rakefile +9 -0
- data/gemfiles/3.2.gemfile +26 -0
- data/gemfiles/4.0.gemfile +26 -0
- data/gemfiles/4.1.gemfile +26 -0
- data/lib/search_cop/arel/visitors.rb +223 -0
- data/lib/search_cop/arel.rb +4 -0
- data/lib/search_cop/grammar_parser.rb +22 -0
- data/lib/search_cop/hash_parser.rb +42 -0
- data/lib/search_cop/query_builder.rb +26 -0
- data/lib/search_cop/query_info.rb +13 -0
- data/lib/search_cop/search_scope.rb +62 -0
- data/lib/search_cop/version.rb +3 -0
- data/lib/search_cop.rb +71 -0
- data/lib/search_cop_grammar/attributes.rb +229 -0
- data/lib/search_cop_grammar/nodes.rb +183 -0
- data/lib/search_cop_grammar.rb +133 -0
- data/lib/search_cop_grammar.treetop +55 -0
- data/search_cop.gemspec +29 -0
- data/test/and_test.rb +27 -0
- data/test/boolean_test.rb +53 -0
- data/test/database.yml +17 -0
- data/test/date_test.rb +75 -0
- data/test/datetime_test.rb +76 -0
- data/test/error_test.rb +17 -0
- data/test/float_test.rb +67 -0
- data/test/fulltext_test.rb +27 -0
- data/test/hash_test.rb +97 -0
- data/test/integer_test.rb +67 -0
- data/test/not_test.rb +27 -0
- data/test/or_test.rb +29 -0
- data/test/scope_test.rb +35 -0
- data/test/search_cop_test.rb +131 -0
- data/test/string_test.rb +84 -0
- data/test/test_helper.rb +150 -0
- metadata +216 -0
data/.gitignore
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
|
2
|
+
addons:
|
3
|
+
postgresql: "9.3"
|
4
|
+
|
5
|
+
before_script:
|
6
|
+
- mysql -e 'create database search_cop;'
|
7
|
+
- psql -c 'create database search_cop;' -U postgres
|
8
|
+
|
9
|
+
rvm:
|
10
|
+
- 1.9.3
|
11
|
+
- 2.0.0
|
12
|
+
- 2.1.1
|
13
|
+
- rbx-2
|
14
|
+
- jruby
|
15
|
+
env:
|
16
|
+
- DATABASE=sqlite
|
17
|
+
- DATABASE=mysql
|
18
|
+
- DATABASE=postgres
|
19
|
+
matrix:
|
20
|
+
allow_failures:
|
21
|
+
- rvm: rbx-2
|
22
|
+
- rvm: jruby
|
23
|
+
|
24
|
+
gemfile:
|
25
|
+
- gemfiles/3.2.gemfile
|
26
|
+
- gemfiles/4.0.gemfile
|
27
|
+
- gemfiles/4.1.gemfile
|
28
|
+
|
29
|
+
install:
|
30
|
+
- "travis_retry bundle install"
|
31
|
+
|
32
|
+
script: "bundle exec rake test"
|
33
|
+
|
data/Appraisals
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
appraise "3.2" do
|
2
|
+
gem "activerecord", "~> 3.2.18"
|
3
|
+
gem "search_cop", :path => "../"
|
4
|
+
end
|
5
|
+
|
6
|
+
appraise "4.0" do
|
7
|
+
gem "activerecord", "~> 4.0.0"
|
8
|
+
gem "search_cop", :path => "../"
|
9
|
+
end
|
10
|
+
|
11
|
+
appraise "4.1" do
|
12
|
+
gem "activerecord", "~> 4.1.0.beta"
|
13
|
+
gem "search_cop", :path => "../"
|
14
|
+
end
|
data/Gemfile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
# Specify your gem's dependencies in search_cop.gemspec
|
4
|
+
gemspec
|
5
|
+
|
6
|
+
platforms :jruby do
|
7
|
+
gem 'activerecord-jdbcmysql-adapter'
|
8
|
+
gem 'activerecord-jdbcsqlite3-adapter'
|
9
|
+
gem 'activerecord-jdbcpostgresql-adapter'
|
10
|
+
end
|
11
|
+
|
12
|
+
platforms :ruby do
|
13
|
+
gem 'sqlite3'
|
14
|
+
gem 'mysql2'
|
15
|
+
gem 'pg'
|
16
|
+
end
|
17
|
+
|
18
|
+
platforms :rbx do
|
19
|
+
gem 'racc'
|
20
|
+
gem 'rubysl', '~> 2.0'
|
21
|
+
gem 'psych'
|
22
|
+
end
|
23
|
+
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Benjamin Vetter
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/MIGRATION.md
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
|
2
|
+
# AttrSearchable to SearchCop
|
3
|
+
|
4
|
+
As the set of features of AttrSearchable grew and grew, it has been neccessary
|
5
|
+
to change its DSL and name, as no `attr_searchable` method is present anymore.
|
6
|
+
The new DSL is cleaner and more concise. Morever, the migration process is
|
7
|
+
simple.
|
8
|
+
|
9
|
+
AttrSearchable:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
class Book < ActiveRecord::Base
|
13
|
+
include AttrSearchable
|
14
|
+
|
15
|
+
scope :search_scope, lambda { eager_load :comments, :users, :user }
|
16
|
+
|
17
|
+
attr_searchable :title, :description
|
18
|
+
attr_searchable :comment => ["comments.title", "comments.message"]
|
19
|
+
attr_searchable :user => ["users.username", "users_books.username"]
|
20
|
+
|
21
|
+
attr_searchable_options :title, :type => :fulltext, :default => true
|
22
|
+
|
23
|
+
attr_searchable_alias :users_books => :user
|
24
|
+
end
|
25
|
+
```
|
26
|
+
|
27
|
+
SearchCop:
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
class Book < ActiveRecord::Base
|
31
|
+
include SearchCop
|
32
|
+
|
33
|
+
search_scope :search do
|
34
|
+
attributes :title, :description
|
35
|
+
attributes :comment => ["comments.title", "comments.message"]
|
36
|
+
attributes :user => ["users.username", "users_books.username"]
|
37
|
+
|
38
|
+
options :title, :type => :fulltext, :default => true
|
39
|
+
|
40
|
+
aliases :users_books => :user
|
41
|
+
|
42
|
+
scope { eager_load :comments, :users, :user }
|
43
|
+
end
|
44
|
+
end
|
45
|
+
```
|
46
|
+
|
47
|
+
# Reflection
|
48
|
+
|
49
|
+
AttrSearchable:
|
50
|
+
|
51
|
+
```ruby
|
52
|
+
Book.searchable_attributes
|
53
|
+
Book.searchable_attribute_options
|
54
|
+
Book.default_searchable_attributes
|
55
|
+
Book.searchable_aliases
|
56
|
+
```
|
57
|
+
|
58
|
+
SearchCop:
|
59
|
+
|
60
|
+
```ruby
|
61
|
+
Book.search_reflection(:search).attributes
|
62
|
+
Book.search_reflection(:search).options
|
63
|
+
Book.search_reflection(:search).default_attributes
|
64
|
+
Book.search_reflection(:search).aliases
|
65
|
+
```
|
66
|
+
|