activerecord-like 1.0.0 → 2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/.travis.yml +13 -3
- data/Appraisals +3 -0
- data/README.md +3 -3
- data/Rakefile +9 -1
- data/activerecord-like.gemspec +7 -1
- data/gemfiles/rails_5_0.gemfile +13 -0
- data/lib/active_record/like.rb +25 -8
- data/lib/active_record/like/version.rb +1 -1
- data/test/unit/like_test.rb +9 -3
- data/test/unit/not_like_test.rb +9 -4
- metadata +49 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fc1b9bf4a828daa0ebcaa68966c12654f34532ca
|
4
|
+
data.tar.gz: 60d7e06e58f04d72ddf0a431faef0bc006e7935e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4ec3097f54125b876a19982ce32081ecc005413420374ae8cb19c447967cfee5c555f4079f58a25c0bad8241cabf6c434868adfdc7e767e83a74e7be87338a96
|
7
|
+
data.tar.gz: c25277c34a1387c51bfb9f33e836436533e636a41fb337959a8b4d70bb3857a3ff80ae5745c8e16de5a1781ee05761f66ebe888ecd5ca9b4176c09546cb28cde
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
@@ -1,13 +1,23 @@
|
|
1
|
+
# Send builds to container-based infrastructure
|
2
|
+
# http://docs.travis-ci.com/user/workers/container-based-infrastructure/
|
3
|
+
sudo: false
|
1
4
|
language: ruby
|
2
5
|
cache: bundler
|
3
6
|
rvm:
|
4
|
-
- 2.
|
5
|
-
- 2.
|
6
|
-
- 2.
|
7
|
+
- 2.2.6
|
8
|
+
- 2.3.3
|
9
|
+
- 2.4.0
|
10
|
+
- ruby-head
|
7
11
|
env:
|
8
12
|
- DB=pg
|
9
13
|
- DB=sqlite3
|
10
14
|
- DB=mysql
|
15
|
+
gemfile:
|
16
|
+
- gemfiles/rails_5_0.gemfile
|
11
17
|
before_script:
|
12
18
|
- psql -c 'create database activerecord_like_test' -U postgres
|
13
19
|
- mysql -e 'create database activerecord_like_test'
|
20
|
+
matrix:
|
21
|
+
fast_finish: true
|
22
|
+
allow_failures:
|
23
|
+
- rvm: ruby-head
|
data/Appraisals
ADDED
data/README.md
CHANGED
@@ -7,9 +7,9 @@
|
|
7
7
|
|
8
8
|
[activerecord-like on Github](https://github.com/ReneB/activerecord-like)
|
9
9
|
|
10
|
-
An Active Record Plugin that allows chaining a more DSL-style 'like' or 'not-like' query to an ActiveRecord::Base#where. Requires Rails
|
10
|
+
An Active Record Plugin that allows chaining a more DSL-style 'like' or 'not-like' query to an ActiveRecord::Base#where. Requires Rails 5 or higher.
|
11
11
|
|
12
|
-
This plugin has been salvaged from the stellar work done by @amatsuda and @claudiob. Most of the code was previously in Active Record master, but was subsequently removed due to, amongst other, scope creep.
|
12
|
+
This plugin has been salvaged from the stellar work done by @amatsuda and @claudiob, and updated to ActiveRecord 5 by @PikachuEXE. Most of the code was previously in Active Record master, but was subsequently removed due to, amongst other, scope creep.
|
13
13
|
Array parameter handling was added by @rzane - thanks!
|
14
14
|
|
15
15
|
## Installation
|
@@ -43,7 +43,7 @@ Post.where.not_like(title: ["%ruby%", "%rails%"])
|
|
43
43
|
```
|
44
44
|
|
45
45
|
## Dependencies
|
46
|
-
|
46
|
+
ActiveRecord 5 or higher
|
47
47
|
|
48
48
|
## Contributing
|
49
49
|
|
data/Rakefile
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
#!/usr/bin/env rake
|
2
2
|
require 'bundler/gem_tasks'
|
3
3
|
require 'rake/testtask'
|
4
|
+
require 'appraisal'
|
4
5
|
|
5
6
|
Rake::TestTask.new do |t|
|
6
7
|
t.libs = ["test"]
|
@@ -10,4 +11,11 @@ Rake::TestTask.new do |t|
|
|
10
11
|
t.ruby_opts = ['-w']
|
11
12
|
end
|
12
13
|
|
13
|
-
|
14
|
+
if !ENV["APPRAISAL_INITIALIZED"] && !ENV["TRAVIS"]
|
15
|
+
task :default do
|
16
|
+
sh "appraisal install && rake appraisal test"
|
17
|
+
end
|
18
|
+
else
|
19
|
+
task :default => [:test]
|
20
|
+
end
|
21
|
+
|
data/activerecord-like.gemspec
CHANGED
@@ -15,5 +15,11 @@ Gem::Specification.new do |gem|
|
|
15
15
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
16
16
|
gem.require_paths = ["lib"]
|
17
17
|
|
18
|
-
gem.add_dependency "activerecord", ">=
|
18
|
+
gem.add_dependency "activerecord", ">= 5.0.0"
|
19
|
+
|
20
|
+
# Required for Travis build to pass
|
21
|
+
gem.add_development_dependency "pg"
|
22
|
+
gem.add_development_dependency "mysql2"
|
23
|
+
|
24
|
+
gem.add_development_dependency "appraisal", "~> 2.0"
|
19
25
|
end
|
data/lib/active_record/like.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
require "active_record"
|
2
2
|
|
3
3
|
module ActiveRecord
|
4
|
-
module
|
5
|
-
module
|
4
|
+
module Like
|
5
|
+
module WhereChainExtensions
|
6
6
|
def like(opts, *rest)
|
7
7
|
opts.each do |k,v|
|
8
8
|
if v.is_a?(Array) && v.empty?
|
@@ -22,17 +22,30 @@ module ActiveRecord
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
-
|
25
|
+
private
|
26
26
|
|
27
27
|
def chain_node(node_type, opts, *rest, &block)
|
28
28
|
@scope.tap do |s|
|
29
|
-
|
30
|
-
|
31
|
-
|
29
|
+
# Assuming `opts` to be `Hash`
|
30
|
+
opts.each_pair do |key, value|
|
31
|
+
# 1. Build a where clause to generate "predicates" & "binds"
|
32
|
+
# 2. Convert "predicates" into the one that matches `node_type` (like/not like)
|
33
|
+
# 3. Re-use binding values to create new where clause
|
34
|
+
equal_where_clause = s.send(:where_clause_factory).build({key => value}, rest)
|
35
|
+
equal_where_clause_predicate = equal_where_clause.send(:predicates).first
|
36
|
+
|
37
|
+
new_predicate = if equal_where_clause_predicate.right.is_a?(Array)
|
38
|
+
nodes = equal_where_clause_predicate.right.map do |expr|
|
39
|
+
node_type.new(equal_where_clause_predicate.left, expr)
|
40
|
+
end
|
32
41
|
Arel::Nodes::Grouping.new block.call(nodes)
|
33
42
|
else
|
34
|
-
node_type.new(
|
43
|
+
node_type.new(equal_where_clause_predicate.left, equal_where_clause_predicate.right)
|
35
44
|
end
|
45
|
+
|
46
|
+
new_where_clause = s.send(:where_clause_factory).build(new_predicate, equal_where_clause.binds)
|
47
|
+
|
48
|
+
s.where_clause += new_where_clause
|
36
49
|
end
|
37
50
|
end
|
38
51
|
end
|
@@ -40,4 +53,8 @@ module ActiveRecord
|
|
40
53
|
end
|
41
54
|
end
|
42
55
|
|
43
|
-
|
56
|
+
ActiveSupport.on_load(:active_record) do
|
57
|
+
ActiveRecord.eager_load!
|
58
|
+
|
59
|
+
ActiveRecord::QueryMethods::WhereChain.send(:include, ::ActiveRecord::Like::WhereChainExtensions)
|
60
|
+
end
|
data/test/unit/like_test.rb
CHANGED
@@ -5,7 +5,7 @@ describe ActiveRecord::QueryMethods::WhereChain do
|
|
5
5
|
it "creates an Arel Matches node in the relation" do
|
6
6
|
relation = Post.where.like(title: '')
|
7
7
|
|
8
|
-
relation.
|
8
|
+
relation.where_clause.send(:predicates).first.must_be_instance_of(Arel::Nodes::Matches)
|
9
9
|
end
|
10
10
|
|
11
11
|
describe "the Arel Node" do
|
@@ -13,11 +13,17 @@ describe ActiveRecord::QueryMethods::WhereChain do
|
|
13
13
|
@attribute = "title"
|
14
14
|
@value = '%value%'
|
15
15
|
|
16
|
-
|
16
|
+
relation = Post.where.like(@attribute => @value)
|
17
|
+
@first_predicate = relation.where_clause.send(:predicates).first
|
18
|
+
@first_bind = relation.where_clause.send(:binds).first
|
17
19
|
end
|
18
20
|
|
19
21
|
it "has the attribute as the left operand" do
|
20
|
-
@
|
22
|
+
@first_predicate.left.name.must_equal @attribute
|
23
|
+
end
|
24
|
+
|
25
|
+
it "has the value as the right operand" do
|
26
|
+
@first_bind.value.must_equal @value
|
21
27
|
end
|
22
28
|
end
|
23
29
|
end
|
data/test/unit/not_like_test.rb
CHANGED
@@ -5,7 +5,7 @@ describe ActiveRecord::QueryMethods::WhereChain do
|
|
5
5
|
it "creates an Arel DoesNotMatch node in the relation" do
|
6
6
|
relation = Post.where.not_like(title: '')
|
7
7
|
|
8
|
-
relation.
|
8
|
+
relation.where_clause.send(:predicates).first.must_be_instance_of(Arel::Nodes::DoesNotMatch)
|
9
9
|
end
|
10
10
|
|
11
11
|
describe "the Arel Node" do
|
@@ -13,13 +13,18 @@ describe ActiveRecord::QueryMethods::WhereChain do
|
|
13
13
|
@attribute = "title"
|
14
14
|
@value = '%value%'
|
15
15
|
|
16
|
-
|
16
|
+
relation = Post.where.like(@attribute => @value)
|
17
|
+
@first_predicate = relation.where_clause.send(:predicates).first
|
18
|
+
@first_bind = relation.where_clause.send(:binds).first
|
17
19
|
end
|
18
20
|
|
19
21
|
it "has the attribute as the left operand" do
|
20
|
-
@
|
22
|
+
@first_predicate.left.name.must_equal @attribute
|
23
|
+
end
|
24
|
+
|
25
|
+
it "has the value as the right operand" do
|
26
|
+
@first_bind.value.must_equal @value
|
21
27
|
end
|
22
28
|
end
|
23
29
|
end
|
24
30
|
end
|
25
|
-
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord-like
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: '2.0'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- René van den Berg
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-01-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -16,14 +16,56 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 5.0.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 5.0.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: pg
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: mysql2
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: appraisal
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '2.0'
|
27
69
|
description: An ActiveRecord plugin providing a higher-level abstraction for SQL 'LIKE'
|
28
70
|
queries
|
29
71
|
email:
|
@@ -34,11 +76,13 @@ extra_rdoc_files: []
|
|
34
76
|
files:
|
35
77
|
- ".gitignore"
|
36
78
|
- ".travis.yml"
|
79
|
+
- Appraisals
|
37
80
|
- Gemfile
|
38
81
|
- LICENSE.txt
|
39
82
|
- README.md
|
40
83
|
- Rakefile
|
41
84
|
- activerecord-like.gemspec
|
85
|
+
- gemfiles/rails_5_0.gemfile
|
42
86
|
- lib/active_record/like.rb
|
43
87
|
- lib/active_record/like/version.rb
|
44
88
|
- lib/activerecord-like.rb
|
@@ -66,7 +110,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
66
110
|
version: '0'
|
67
111
|
requirements: []
|
68
112
|
rubyforge_project:
|
69
|
-
rubygems_version: 2.
|
113
|
+
rubygems_version: 2.5.1
|
70
114
|
signing_key:
|
71
115
|
specification_version: 4
|
72
116
|
summary: 'ActiveRecord::Like provides ActiveRecord::Base with where.like(attribute:
|