minidusen 0.7.0 → 0.8.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
  SHA1:
3
- metadata.gz: 21b9abdca5644bbe2c9d7266988f8a0a22927435
4
- data.tar.gz: 8fde451ba5ee361aa2c7ee3377ac195edd641d0e
3
+ metadata.gz: 5bd84ad91feb76221d8d3f3b23995fceebf512b9
4
+ data.tar.gz: cf0b8b10d9caab23d4b4f4b7bb5c9d22ed185502
5
5
  SHA512:
6
- metadata.gz: fbd3c16faed08b0ec651898c609f78da008688701513dbfa372f495327540d14d283f031d9723d75a8425069499aab945129ee794b0bd1aa85699bc9bcd36e6c
7
- data.tar.gz: fc869ed7bd8b21f1babd9c433bf6c5c31383188a6d9672e3a43680591bde2989dbd61ce4678d9ff525a1ef2d266935fd3da245a288eb3b110ba0c00846d01812
6
+ metadata.gz: a2002af4871106833bd6d2e861fa6cf78b879837e493668cfb5490749a8e99a5ed065d375a55b0cb1e7d6640be2863447b584574230306eca1e7497704353102
7
+ data.tar.gz: 9e22eb209770e120e23de9d8ab3c19c07ecb019bbb6f7aaa8ee4dc8d230c6a4a3b77ce47cec6eeb4735491615a64ef6998e28fb50684c742c75f2986d533af75
data/.travis.yml CHANGED
@@ -1,30 +1,34 @@
1
1
  language: ruby
2
+
2
3
  rvm:
3
- - "2.1.8"
4
- - "2.3.1"
4
+ - 2.1.8
5
+ - 2.2.4
6
+ - 2.3.1
7
+
5
8
  gemfile:
6
9
  - gemfiles/Gemfile.3.2.mysql2
7
10
  - gemfiles/Gemfile.4.2.mysql2
8
11
  - gemfiles/Gemfile.4.2.pg
9
12
  - gemfiles/Gemfile.5.0.mysql2
10
13
  - gemfiles/Gemfile.5.0.pg
14
+
11
15
  before_script:
12
16
  - psql -c 'create database minidusen_test;' -U postgres
13
17
  - mysql -e 'create database IF NOT EXISTS minidusen_test;'
18
+
14
19
  script: bundle exec rspec spec
20
+
15
21
  sudo: false
22
+
16
23
  cache: bundler
24
+
17
25
  notifications:
18
26
  email:
19
27
  - fail@makandra.de
20
- branches:
21
- only:
22
- - master
28
+
23
29
  matrix:
24
30
  exclude:
25
- - rvm: "2.3.1"
26
- gemfile: gemfiles/Gemfile.3.2.mysql2
27
- - rvm: "2.1.8"
31
+ - rvm: 2.1.8
28
32
  gemfile: gemfiles/Gemfile.5.0.mysql2
29
- - rvm: "2.1.8"
33
+ - rvm: 2.1.8
30
34
  gemfile: gemfiles/Gemfile.5.0.pg
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ # Minidusen change log
2
+
3
+ ## 0.8.0 (2017-08-21)
4
+
5
+ - Filters are now run in the context of the filter instance, not the filter class. This allows using private methods or instance variables.
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2013 Henning Koch
1
+ Copyright (c) 2016 Henning Koch
2
2
 
3
3
  MIT License
4
4
 
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- Minidusen [![Build Status](https://secure.travis-ci.org/makandra/minidusen.png?branch=master)](https://travis-ci.org/makandra/minidusen)
1
+ Minidusen [![Build Status](https://travis-ci.org/makandra/minidusen.svg?branch=master)](https://travis-ci.org/makandra/minidusen)
2
2
  =========
3
3
 
4
4
  Low-tech search solution for ActiveRecord with MySQL or PostgreSQL
@@ -7,6 +7,13 @@ Low-tech search solution for ActiveRecord with MySQL or PostgreSQL
7
7
  Minidusen lets you filter ActiveRecord models with a single query string.
8
8
  It works with your existing MySQL or PostgreSQL schema by mostly relying on simple `LIKE` queries. No additional indexes, tables or indexing databases are required.
9
9
 
10
+ This makes Minidusen a quick way to implement find-as-you-type filters for index views:
11
+
12
+ ![A list of records filtered by a query](https://raw.githubusercontent.com/makandra/minidusen/master/doc/filtered_index_view.cropped.png)
13
+
14
+
15
+ ### Supported queries
16
+
10
17
  Minidusen accepts a single, Google-like query string and converts it into `WHERE` conditions for [an ActiveRecord scope](http://guides.rubyonrails.org/active_record_querying.html#conditions).
11
18
 
12
19
  The following type of queries are supported:
@@ -18,11 +25,14 @@ The following type of queries are supported:
18
25
  - `filetype:pdf` (developer-defined filter for file type)
19
26
  - `some words 'a phrase' filetype:pdf -excluded -'excluded phrase' -filetype:pdf` (combination of the above)
20
27
 
21
- Minidusen is a quick way to implement find-as-you-type filters for index views:
22
28
 
23
- ![A list of records filtered by a query](https://raw.githubusercontent.com/makandra/minidusen/master/doc/filtered_index_view.cropped.png)
29
+ ### Limitations
30
+
31
+ Since Minidusen doesn't use an index, it scales linearly with the amount of of text that needs to be searched. Yet `LIKE` queries are pretty fast and we have found this low-tech approach to scale well for many thousand records.
24
32
 
25
- We have found it to scale well for many thousand records. It's probably not a good idea to use Minidusen for hundreds of thousands of records or very long text columns. For this we recommend to use PostgreSQL with [pg_search](https://github.com/Casecommons/pg_search) or full-text databases like [Solr](https://github.com/sunspot/sunspot).
33
+ It's probably not a good idea to use Minidusen for hundreds of thousands of records, or for very long text columns. For this we recommend to use PostgreSQL with [pg_search](https://github.com/Casecommons/pg_search) or full-text databases like [Solr](https://github.com/sunspot/sunspot).
34
+
35
+ Another limitation of Minidusen is that it only *filters*, but does not *rank*. A record either matches or not. Minidusen won't tell you if one record matches *better* than another record.
26
36
 
27
37
 
28
38
  Installation
@@ -134,17 +144,17 @@ Google supports queries like `filetype:pdf` that filters records by some criteri
134
144
  Let's support a query like `email:foo@bar.com` to explictly search for a contact's email address, without filtering against other columns.
135
145
 
136
146
  We can learn this syntax by adding a `filter:email` instruction
137
- to our `ContactFilter` class`:
147
+ to our `ContactFilter` class:
138
148
 
139
149
  ```ruby
140
150
  class ContactFilter
141
151
  include Minidusen::Filter
142
152
 
143
- search_by :email do |scope, email|
153
+ filter :email do |scope, email|
144
154
  scope.where(emai: email)
145
155
  end
146
156
 
147
- search_by :text do |scope, phrases|
157
+ filter :text do |scope, phrases|
148
158
  columns = [:name, :email]
149
159
  scope.where_like(columns => phrases)
150
160
  end
@@ -186,13 +196,12 @@ Development
186
196
  -----------
187
197
 
188
198
  - There are tests in `spec`. We only accept PRs with tests.
189
- - We currently develop using Ruby 2.2.4 (see `.ruby-version`) since that version works for all versions of ActiveRecord that we support.
190
- - TravisCI will test additional Ruby versions (2.1.8 and 2.3.1)
199
+ - We currently develop using Ruby 2.2.4 (see `.ruby-version`) since that version works for all versions of ActiveRecord that we support. Travis CI will test additional Ruby versions (2.1.8 and 2.3.1).
191
200
  - Put your database credentials into `spec/support/database.yml`. There's a `database.sample.yml` you can use as a template.
192
201
  - Create a database `minidusen_test` in both MySQL and PostgreSQL.
193
202
  - There are gem bundles in `gemfiles` for each combination of ActiveRecord version and database type that we support.
194
- - You can bundle all test applications by saying `bundle exec rake all:install`
195
- - You can run specs from the project root by saying `bundle exec rake all:spec`.
203
+ - You can bundle all test applications by saying `bundle exec rake matrix:install`
204
+ - You can run specs from the project root by saying `bundle exec rake matrix:spec`. This will run all gemfiles compatible with your current Ruby.
196
205
 
197
206
  If you would like to contribute:
198
207
 
data/Rakefile CHANGED
@@ -1,42 +1,9 @@
1
1
  require 'rake'
2
2
  require 'bundler/gem_tasks'
3
-
4
- desc 'Default: Run all specs.'
5
- task :default => 'all:spec'
6
-
7
- namespace :all do
8
-
9
- desc "Run specs on all versions"
10
- task :spec do
11
- success = true
12
- for_each_gemfile do
13
- success &= system("bundle exec rspec spec")
14
- end
15
- fail "Tests failed" unless success
16
- end
17
-
18
- desc "Bundle all versions"
19
- task :install do
20
- for_each_gemfile do
21
- system('bundle install')
22
- end
23
- end
24
-
25
- desc "Update all versions"
26
- task :update do
27
- for_each_gemfile do
28
- system('bundle update')
29
- end
30
- end
31
-
3
+ begin
4
+ require 'gemika/tasks'
5
+ rescue LoadError
6
+ puts 'Run `gem install gemika` for additional tasks'
32
7
  end
33
8
 
34
- def for_each_gemfile
35
- version = ENV['VERSION'] || '*'
36
- Dir["gemfiles/Gemfile.#{version}"].sort.each do |gemfile|
37
- next if gemfile =~ /.lock/
38
- puts '', "\033[44m#{gemfile}\033[0m", ''
39
- ENV['BUNDLE_GEMFILE'] = gemfile
40
- yield
41
- end
42
- end
9
+ task :default => 'matrix:spec'
@@ -1,10 +1,16 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
+ # Runtime dependencies
3
4
  gem 'activerecord', '=3.2.22'
4
- gem 'rspec', '~> 3.4'
5
5
  gem 'mysql2', '= 0.3.17'
6
+ gem 'i18n', '=0.6.11' # 0.7 no longer builds for Ruby 1.8.7
6
7
 
8
+ # Development dependencies
9
+ gem 'rake'
10
+ gem 'database_cleaner'
11
+ gem 'rspec', '~> 3.4'
7
12
  gem 'byebug'
13
+ gem 'gemika'
8
14
 
15
+ # Gem under test
9
16
  gem 'minidusen', :path => '..'
10
- gem 'i18n', '=0.6.11' # 0.7 no longer builds for Ruby 1.8.7
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- minidusen (0.7.0)
4
+ minidusen (0.8.0)
5
5
  activerecord (>= 3.2)
6
6
  activesupport (>= 3.2)
7
7
  edge_rider (>= 0.2.5)
@@ -22,27 +22,30 @@ GEM
22
22
  multi_json (~> 1.0)
23
23
  arel (3.0.3)
24
24
  builder (3.0.4)
25
- byebug (8.2.0)
25
+ byebug (9.0.5)
26
+ database_cleaner (1.5.3)
26
27
  diff-lcs (1.2.5)
27
28
  edge_rider (0.3.1)
28
29
  activerecord
30
+ gemika (0.3.2)
29
31
  i18n (0.6.11)
30
- multi_json (1.11.2)
32
+ multi_json (1.12.1)
31
33
  mysql2 (0.3.17)
32
- rspec (3.4.0)
33
- rspec-core (~> 3.4.0)
34
- rspec-expectations (~> 3.4.0)
35
- rspec-mocks (~> 3.4.0)
36
- rspec-core (3.4.1)
37
- rspec-support (~> 3.4.0)
38
- rspec-expectations (3.4.0)
34
+ rake (11.3.0)
35
+ rspec (3.5.0)
36
+ rspec-core (~> 3.5.0)
37
+ rspec-expectations (~> 3.5.0)
38
+ rspec-mocks (~> 3.5.0)
39
+ rspec-core (3.5.3)
40
+ rspec-support (~> 3.5.0)
41
+ rspec-expectations (3.5.0)
39
42
  diff-lcs (>= 1.2.0, < 2.0)
40
- rspec-support (~> 3.4.0)
41
- rspec-mocks (3.4.1)
43
+ rspec-support (~> 3.5.0)
44
+ rspec-mocks (3.5.0)
42
45
  diff-lcs (>= 1.2.0, < 2.0)
43
- rspec-support (~> 3.4.0)
44
- rspec-support (3.4.1)
45
- tzinfo (0.3.46)
46
+ rspec-support (~> 3.5.0)
47
+ rspec-support (3.5.0)
48
+ tzinfo (0.3.51)
46
49
 
47
50
  PLATFORMS
48
51
  ruby
@@ -50,9 +53,12 @@ PLATFORMS
50
53
  DEPENDENCIES
51
54
  activerecord (= 3.2.22)
52
55
  byebug
56
+ database_cleaner
57
+ gemika
53
58
  i18n (= 0.6.11)
54
59
  minidusen!
55
60
  mysql2 (= 0.3.17)
61
+ rake
56
62
  rspec (~> 3.4)
57
63
 
58
64
  BUNDLED WITH
@@ -1,9 +1,15 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
+ # Runtime dependencies
3
4
  gem 'activerecord', '~>4.2.1'
4
- gem 'rspec', '~>3.4'
5
5
  gem 'mysql2', '~> 0.3.17'
6
6
 
7
+ # Development dependencies
8
+ gem 'database_cleaner'
9
+ gem 'rake'
10
+ gem 'rspec', '~>3.4'
7
11
  gem 'byebug'
12
+ gem 'gemika'
8
13
 
14
+ # Gem under test
9
15
  gem 'minidusen', :path => '..'
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- minidusen (0.7.0)
4
+ minidusen (0.8.0)
5
5
  activerecord (>= 3.2)
6
6
  activesupport (>= 3.2)
7
7
  edge_rider (>= 0.2.5)
@@ -9,14 +9,14 @@ PATH
9
9
  GEM
10
10
  remote: https://rubygems.org/
11
11
  specs:
12
- activemodel (4.2.5)
13
- activesupport (= 4.2.5)
12
+ activemodel (4.2.7.1)
13
+ activesupport (= 4.2.7.1)
14
14
  builder (~> 3.1)
15
- activerecord (4.2.5)
16
- activemodel (= 4.2.5)
17
- activesupport (= 4.2.5)
15
+ activerecord (4.2.7.1)
16
+ activemodel (= 4.2.7.1)
17
+ activesupport (= 4.2.7.1)
18
18
  arel (~> 6.0)
19
- activesupport (4.2.5)
19
+ activesupport (4.2.7.1)
20
20
  i18n (~> 0.7)
21
21
  json (~> 1.7, >= 1.7.7)
22
22
  minitest (~> 5.1)
@@ -24,27 +24,30 @@ GEM
24
24
  tzinfo (~> 1.1)
25
25
  arel (6.0.3)
26
26
  builder (3.2.2)
27
- byebug (8.2.0)
27
+ byebug (9.0.5)
28
+ database_cleaner (1.5.3)
28
29
  diff-lcs (1.2.5)
29
30
  edge_rider (0.3.1)
30
31
  activerecord
32
+ gemika (0.3.2)
31
33
  i18n (0.7.0)
32
34
  json (1.8.3)
33
- minitest (5.8.3)
34
- mysql2 (0.3.20)
35
- rspec (3.4.0)
36
- rspec-core (~> 3.4.0)
37
- rspec-expectations (~> 3.4.0)
38
- rspec-mocks (~> 3.4.0)
39
- rspec-core (3.4.1)
40
- rspec-support (~> 3.4.0)
41
- rspec-expectations (3.4.0)
35
+ minitest (5.9.0)
36
+ mysql2 (0.3.21)
37
+ rake (11.3.0)
38
+ rspec (3.5.0)
39
+ rspec-core (~> 3.5.0)
40
+ rspec-expectations (~> 3.5.0)
41
+ rspec-mocks (~> 3.5.0)
42
+ rspec-core (3.5.3)
43
+ rspec-support (~> 3.5.0)
44
+ rspec-expectations (3.5.0)
42
45
  diff-lcs (>= 1.2.0, < 2.0)
43
- rspec-support (~> 3.4.0)
44
- rspec-mocks (3.4.1)
46
+ rspec-support (~> 3.5.0)
47
+ rspec-mocks (3.5.0)
45
48
  diff-lcs (>= 1.2.0, < 2.0)
46
- rspec-support (~> 3.4.0)
47
- rspec-support (3.4.1)
49
+ rspec-support (~> 3.5.0)
50
+ rspec-support (3.5.0)
48
51
  thread_safe (0.3.5)
49
52
  tzinfo (1.2.2)
50
53
  thread_safe (~> 0.1)
@@ -55,8 +58,11 @@ PLATFORMS
55
58
  DEPENDENCIES
56
59
  activerecord (~> 4.2.1)
57
60
  byebug
61
+ database_cleaner
62
+ gemika
58
63
  minidusen!
59
64
  mysql2 (~> 0.3.17)
65
+ rake
60
66
  rspec (~> 3.4)
61
67
 
62
68
  BUNDLED WITH
@@ -1,9 +1,15 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
+ # Runtime dependencies
3
4
  gem 'activerecord', '~>4.2.1'
4
- gem 'rspec', '~>3.4'
5
5
  gem 'pg'
6
6
 
7
+ # Development dependencies
8
+ gem 'rake'
9
+ gem 'database_cleaner'
10
+ gem 'rspec', '~>3.4'
7
11
  gem 'byebug'
12
+ gem 'gemika'
8
13
 
14
+ # Gem under test
9
15
  gem 'minidusen', :path => '..'
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- minidusen (0.7.0)
4
+ minidusen (0.8.0)
5
5
  activerecord (>= 3.2)
6
6
  activesupport (>= 3.2)
7
7
  edge_rider (>= 0.2.5)
@@ -9,14 +9,14 @@ PATH
9
9
  GEM
10
10
  remote: https://rubygems.org/
11
11
  specs:
12
- activemodel (4.2.5)
13
- activesupport (= 4.2.5)
12
+ activemodel (4.2.7.1)
13
+ activesupport (= 4.2.7.1)
14
14
  builder (~> 3.1)
15
- activerecord (4.2.5)
16
- activemodel (= 4.2.5)
17
- activesupport (= 4.2.5)
15
+ activerecord (4.2.7.1)
16
+ activemodel (= 4.2.7.1)
17
+ activesupport (= 4.2.7.1)
18
18
  arel (~> 6.0)
19
- activesupport (4.2.5)
19
+ activesupport (4.2.7.1)
20
20
  i18n (~> 0.7)
21
21
  json (~> 1.7, >= 1.7.7)
22
22
  minitest (~> 5.1)
@@ -24,27 +24,30 @@ GEM
24
24
  tzinfo (~> 1.1)
25
25
  arel (6.0.3)
26
26
  builder (3.2.2)
27
- byebug (8.2.0)
27
+ byebug (9.0.5)
28
+ database_cleaner (1.5.3)
28
29
  diff-lcs (1.2.5)
29
30
  edge_rider (0.3.1)
30
31
  activerecord
32
+ gemika (0.3.2)
31
33
  i18n (0.7.0)
32
34
  json (1.8.3)
33
- minitest (5.8.3)
34
- pg (0.18.4)
35
- rspec (3.4.0)
36
- rspec-core (~> 3.4.0)
37
- rspec-expectations (~> 3.4.0)
38
- rspec-mocks (~> 3.4.0)
39
- rspec-core (3.4.1)
40
- rspec-support (~> 3.4.0)
41
- rspec-expectations (3.4.0)
35
+ minitest (5.9.0)
36
+ pg (0.19.0)
37
+ rake (11.3.0)
38
+ rspec (3.5.0)
39
+ rspec-core (~> 3.5.0)
40
+ rspec-expectations (~> 3.5.0)
41
+ rspec-mocks (~> 3.5.0)
42
+ rspec-core (3.5.3)
43
+ rspec-support (~> 3.5.0)
44
+ rspec-expectations (3.5.0)
42
45
  diff-lcs (>= 1.2.0, < 2.0)
43
- rspec-support (~> 3.4.0)
44
- rspec-mocks (3.4.1)
46
+ rspec-support (~> 3.5.0)
47
+ rspec-mocks (3.5.0)
45
48
  diff-lcs (>= 1.2.0, < 2.0)
46
- rspec-support (~> 3.4.0)
47
- rspec-support (3.4.1)
49
+ rspec-support (~> 3.5.0)
50
+ rspec-support (3.5.0)
48
51
  thread_safe (0.3.5)
49
52
  tzinfo (1.2.2)
50
53
  thread_safe (~> 0.1)
@@ -55,8 +58,11 @@ PLATFORMS
55
58
  DEPENDENCIES
56
59
  activerecord (~> 4.2.1)
57
60
  byebug
61
+ database_cleaner
62
+ gemika
58
63
  minidusen!
59
64
  pg
65
+ rake
60
66
  rspec (~> 3.4)
61
67
 
62
68
  BUNDLED WITH
@@ -1,9 +1,15 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
+ # Runtime dependencies
3
4
  gem 'activerecord', '~>5.0.0'
4
- gem 'rspec', '~>3.5'
5
5
  gem 'mysql2', '~>0.4.4'
6
6
 
7
+ # Development dependencies
8
+ gem 'rake'
9
+ gem 'database_cleaner'
10
+ gem 'rspec', '~>3.5'
7
11
  gem 'byebug'
12
+ gem 'gemika'
8
13
 
14
+ # Gem under test
9
15
  gem 'minidusen', :path => '..'
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- minidusen (0.7.0)
4
+ minidusen (0.8.0)
5
5
  activerecord (>= 3.2)
6
6
  activesupport (>= 3.2)
7
7
  edge_rider (>= 0.2.5)
@@ -23,12 +23,15 @@ GEM
23
23
  arel (7.1.2)
24
24
  byebug (9.0.5)
25
25
  concurrent-ruby (1.0.2)
26
+ database_cleaner (1.5.3)
26
27
  diff-lcs (1.2.5)
27
28
  edge_rider (0.3.1)
28
29
  activerecord
30
+ gemika (0.3.2)
29
31
  i18n (0.7.0)
30
32
  minitest (5.9.0)
31
33
  mysql2 (0.4.4)
34
+ rake (11.3.0)
32
35
  rspec (3.5.0)
33
36
  rspec-core (~> 3.5.0)
34
37
  rspec-expectations (~> 3.5.0)
@@ -52,8 +55,11 @@ PLATFORMS
52
55
  DEPENDENCIES
53
56
  activerecord (~> 5.0.0)
54
57
  byebug
58
+ database_cleaner
59
+ gemika
55
60
  minidusen!
56
61
  mysql2 (~> 0.4.4)
62
+ rake
57
63
  rspec (~> 3.5)
58
64
 
59
65
  BUNDLED WITH
@@ -1,9 +1,15 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
+ # Runtime dependencies
3
4
  gem 'activerecord', '~>5.0.0'
4
- gem 'rspec', '~>3.5'
5
5
  gem 'pg', '~>0.18.4'
6
6
 
7
+ # Development dependendcies
8
+ gem 'rake'
9
+ gem 'database_cleaner'
10
+ gem 'rspec', '~>3.5'
7
11
  gem 'byebug'
12
+ gem 'gemika'
8
13
 
14
+ # Gem under test
9
15
  gem 'minidusen', :path => '..'
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- minidusen (0.7.0)
4
+ minidusen (0.8.0)
5
5
  activerecord (>= 3.2)
6
6
  activesupport (>= 3.2)
7
7
  edge_rider (>= 0.2.5)
@@ -23,12 +23,15 @@ GEM
23
23
  arel (7.1.2)
24
24
  byebug (9.0.5)
25
25
  concurrent-ruby (1.0.2)
26
+ database_cleaner (1.5.3)
26
27
  diff-lcs (1.2.5)
27
28
  edge_rider (0.3.1)
28
29
  activerecord
30
+ gemika (0.3.2)
29
31
  i18n (0.7.0)
30
32
  minitest (5.9.0)
31
33
  pg (0.18.4)
34
+ rake (11.3.0)
32
35
  rspec (3.5.0)
33
36
  rspec-core (~> 3.5.0)
34
37
  rspec-expectations (~> 3.5.0)
@@ -52,8 +55,11 @@ PLATFORMS
52
55
  DEPENDENCIES
53
56
  activerecord (~> 5.0.0)
54
57
  byebug
58
+ database_cleaner
59
+ gemika
55
60
  minidusen!
56
61
  pg (~> 0.18.4)
62
+ rake
57
63
  rspec (~> 3.5)
58
64
 
59
65
  BUNDLED WITH
@@ -18,7 +18,7 @@ module Minidusen
18
18
  end
19
19
 
20
20
  def filter(scope, query)
21
- minidusen_syntax.search(scope, query)
21
+ minidusen_syntax.search(self, scope, query)
22
22
  end
23
23
 
24
24
  private
@@ -10,12 +10,12 @@ module Minidusen
10
10
  @scopers[field] = scoper
11
11
  end
12
12
 
13
- def search(root_scope, query)
13
+ def search(instance, root_scope, query)
14
14
  query = parse(query) if query.is_a?(String)
15
15
  query = query.condensed
16
- matches = apply_query(root_scope, query.include)
16
+ matches = apply_query(instance, root_scope, query.include)
17
17
  if query.exclude.any?
18
- matches = append_excludes(matches, query.exclude)
18
+ matches = append_excludes(instance, matches, query.exclude)
19
19
  end
20
20
  matches
21
21
  end
@@ -34,17 +34,17 @@ module Minidusen
34
34
  scope.where('1=2')
35
35
  end
36
36
 
37
- def apply_query(root_scope, query)
37
+ def apply_query(instance, root_scope, query)
38
38
  scope = root_scope
39
39
  query.each do |token|
40
40
  scoper = @scopers[token.field] || NONE
41
- scope = scoper.call(scope, token.value)
41
+ scope = instance.instance_exec(scope, token.value, &scoper)
42
42
  end
43
43
  scope
44
44
  end
45
45
 
46
- def append_excludes(matches, exclude_query)
47
- excluded_records = apply_query(matches.origin_class, exclude_query)
46
+ def append_excludes(instance, matches, exclude_query)
47
+ excluded_records = apply_query(instance, matches.origin_class, exclude_query)
48
48
  qualified_id_field = Util.qualify_column_name(excluded_records, excluded_records.primary_key)
49
49
  exclude_sql = "#{qualified_id_field} NOT IN (#{excluded_records.select(qualified_id_field).to_sql})"
50
50
  matches.where(exclude_sql)
@@ -2,7 +2,7 @@ module Minidusen
2
2
  module Util
3
3
  extend self
4
4
 
5
- def postgres?(scope)
5
+ def postgresql?(scope)
6
6
  adapter_name = scope.connection.class.name
7
7
  adapter_name =~ /postgres/i
8
8
  end
@@ -12,7 +12,7 @@ module Minidusen
12
12
  end
13
13
 
14
14
  def ilike_operator(scope)
15
- if postgres?(scope)
15
+ if postgresql?(scope)
16
16
  'ILIKE'
17
17
  else
18
18
  'LIKE'
@@ -20,7 +20,7 @@ module Minidusen
20
20
  end
21
21
 
22
22
  def regexp_operator(scope)
23
- if postgres?(scope)
23
+ if postgresql?(scope)
24
24
  '~'
25
25
  else
26
26
  'REGEXP'
@@ -1,3 +1,3 @@
1
1
  module Minidusen
2
- VERSION = '0.7.0'
2
+ VERSION = '0.8.0'
3
3
  end
@@ -181,6 +181,27 @@ describe Minidusen::Filter do
181
181
 
182
182
  end
183
183
 
184
+ it 'runs filter in the instance context' do
185
+ filter_class = Class.new do
186
+ include Minidusen::Filter
187
+
188
+ def columns
189
+ [:name, :email, :city]
190
+ end
191
+
192
+ filter :text do |scope, phrases|
193
+ scope.report_instance(self)
194
+ scope.where_like(columns => phrases)
195
+ end
196
+ end
197
+ filter_instance = filter_class.new
198
+
199
+ match = User.create!(:name => 'Abraham')
200
+ no_match = User.create!(:name => 'Elizabath')
201
+ expect(User).to receive(:report_instance).with(filter_instance)
202
+ filter_instance.filter(User, 'Abra').to_a.should == [match]
203
+ end
204
+
184
205
  end
185
206
 
186
207
  describe '#minidusen_syntax' do
data/spec/spec_helper.rb CHANGED
@@ -2,28 +2,15 @@ $: << File.join(File.dirname(__FILE__), "/../../lib" )
2
2
 
3
3
  require 'minidusen'
4
4
  require 'byebug'
5
+ require 'gemika'
5
6
 
6
7
  ActiveRecord::Base.default_timezone = :local
7
8
 
8
9
  Dir["#{File.dirname(__FILE__)}/support/*.rb"].sort.each {|f| require f}
9
10
  Dir["#{File.dirname(__FILE__)}/shared_examples/*.rb"].sort.each {|f| require f}
10
11
 
12
+ Gemika::RSpec.configure_clean_database_before_example
11
13
 
12
- RSpec.configure do |config|
13
-
14
+ Gemika::RSpec.configure do |config|
14
15
  config.expect_with(:rspec) { |c| c.syntax = [:should, :expect] }
15
-
16
- config.around do |example|
17
- if example.metadata.fetch(:rollback, true)
18
- ActiveRecord::Base.transaction do
19
- begin
20
- example.run
21
- ensure
22
- raise ActiveRecord::Rollback
23
- end
24
- end
25
- else
26
- example.run
27
- end
28
- end
29
16
  end
@@ -1,31 +1,4 @@
1
- require 'yaml'
2
-
3
- database_config_file = ENV['TRAVIS'] ? 'database.travis.yml' : 'database.yml'
4
- database_config_file = File.join(File.dirname(__FILE__), database_config_file)
5
- File.exists?(database_config_file) or raise "Missing database configuration file: #{database_config_file}"
6
-
7
- database_config = YAML.load_file(database_config_file)
8
-
9
- connection_config = {}
10
-
11
- case ENV['BUNDLE_GEMFILE']
12
- when /pg/, /postgres/
13
- connection_config = database_config['postgresql'].merge(adapter: 'postgresql')
14
- when /mysql2/
15
- connection_config = database_config['mysql'].merge(adapter: 'mysql2', encoding: 'utf8')
16
- else
17
- raise "Unknown database type in Gemfile suffix: #{ENV['BUNDLE_GEMFILE']}"
18
- end
19
-
20
- ActiveRecord::Base.establish_connection(connection_config)
21
-
22
-
23
- connection = ::ActiveRecord::Base.connection
24
- connection.tables.each do |table|
25
- connection.drop_table table
26
- end
27
-
28
- ActiveRecord::Migration.class_eval do
1
+ Gemika::Database.new.rewrite_schema! do
29
2
 
30
3
  create_table :users do |t|
31
4
  t.string :name
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: minidusen
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henning Koch
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-15 00:00:00.000000000 Z
11
+ date: 2017-08-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -62,6 +62,7 @@ files:
62
62
  - ".rspec"
63
63
  - ".ruby-version"
64
64
  - ".travis.yml"
65
+ - CHANGELOG.md
65
66
  - LICENSE
66
67
  - README.md
67
68
  - Rakefile