activerecord-like 1.0.0 → 6.1.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
- SHA1:
3
- metadata.gz: 7d5747b7416a46d6d651022ba3fa6924fd8db7a0
4
- data.tar.gz: a12c215ff69771f33fc772c81c52328d553afc3e
2
+ SHA256:
3
+ metadata.gz: 17697882d9797eb85a6b4a1e80d80c49b5fffd8ab8cd8f12f8b2d72214b96dba
4
+ data.tar.gz: 6270ce1472c08edff4c6bed332cdc291273d240069c47eabfcae5400ebad67a9
5
5
  SHA512:
6
- metadata.gz: 28e1151781fee66992b46a476bf7390f56febd409616f31af9cf41a5c1c8e2354df120fb2927bc7a12983e04db7ff34947427cb1314c6ddfe36a38dd38c468d3
7
- data.tar.gz: bcf5e1ee0ae802a3bdbf6ea1444e720e5e2a74ad540b88cf9e538ebdf0e35586172269bc54a932d3e255ee0c11d431ace76d79b43a8d3b119ef6f5e3769f5a20
6
+ metadata.gz: 8be7e5510726ad3f76ec93a75720ce28e37e04c13ed7f386cdd43d0faadee816f1cf06073f36a328f0a691ede4e34e6a8780f45fd49a7d6b2b27a1edc828fe8a
7
+ data.tar.gz: a044ba63ce7215909b9cd807130cf19b5fbe35854afd1291d4e1b05e260adcaa076b1ddd65d52702b72d9ee9a928a353ba774f78e73206a0f16eb3acbf915f7a
data/.gitignore CHANGED
@@ -16,3 +16,6 @@ test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
18
  .rvmrc
19
+
20
+ # Ignore Appraisal related files
21
+ gemfiles/*.gemfile.lock
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
6
+ services:
7
+ - postgresql
8
+ - mysql
3
9
  rvm:
4
- - 2.1.9
5
- - 2.2.5
6
- - 2.3.1
10
+ - 2.7.5
11
+ - 3.0.3
12
+ - ruby-head
7
13
  env:
8
14
  - DB=pg
9
15
  - DB=sqlite3
10
16
  - DB=mysql
11
- before_script:
12
- - psql -c 'create database activerecord_like_test' -U postgres
13
- - mysql -e 'create database activerecord_like_test'
17
+ gemfile:
18
+ - gemfiles/rails_6_0.gemfile
19
+ - gemfiles/rails_6_1.gemfile
20
+ matrix:
21
+ fast_finish: true
22
+ allow_failures:
23
+ - rvm: ruby-head
data/Appraisals ADDED
@@ -0,0 +1,5 @@
1
+ ("6.0".."6.1").each do |version|
2
+ appraise "rails_#{version.tr('.', '_')}" do
3
+ gem "activerecord", "~> #{version}.0"
4
+ end
5
+ end
data/Gemfile CHANGED
@@ -1,20 +1,3 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gem 'activerecord', '>= 4.0.0'
4
-
5
- group :test do
6
- gem 'rake'
7
-
8
- case ENV['DB']
9
- when 'pg'
10
- gem 'pg'
11
- when 'mysql'
12
- gem 'mysql2'
13
- else
14
- gem 'sqlite3'
15
- end
16
-
17
- gem 'minitest', '>= 3'
18
- end
19
-
20
3
  gemspec
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 4 beta or higher.
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 and 5.2 by @robotdana. Most of the code was previously in Active Record master, but was subsequently removed due to, amongst other, scope creep (see discussion [here](https://github.com/rails/rails/commit/8d02afeaee8993bd0fde69687fdd9bf30921e805)).
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
- Does not work with Arel 4.0.1 or lower or Arel 5.0.0. Do a `bundle update arel` to get the latest Arel that is compatible with your ActiveRecord version (4.0 for ActiveRecord 4.0, 5.0 for ActiveRecord 4.1).
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
- task :default => :test
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
+
@@ -15,5 +15,16 @@ 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", ">= 4.0.0"
18
+ gem.add_dependency "activerecord", "~> 6.0", ">= 6.0.0"
19
+
20
+ # Required for Travis build to pass
21
+ gem.add_development_dependency "pg"
22
+ gem.add_development_dependency "mysql2"
23
+ gem.add_development_dependency "sqlite3"
24
+
25
+ gem.add_development_dependency "rake"
26
+
27
+ gem.add_development_dependency "minitest", ">= 3"
28
+
29
+ gem.add_development_dependency "appraisal", "~> 2.0"
19
30
  end
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activerecord", "~> 6.0.0"
6
+
7
+ gemspec path: "../"
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activerecord", "~> 6.1.0"
6
+
7
+ gemspec path: "../"
@@ -1,5 +1,5 @@
1
1
  module ActiveRecord
2
2
  module Like
3
- VERSION = "1.0.0"
3
+ VERSION = "6.1.0"
4
4
  end
5
5
  end
@@ -1,8 +1,8 @@
1
1
  require "active_record"
2
2
 
3
3
  module ActiveRecord
4
- module QueryMethods
5
- module Like
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,44 @@ module ActiveRecord
22
22
  end
23
23
  end
24
24
 
25
- private
25
+ private
26
26
 
27
27
  def chain_node(node_type, opts, *rest, &block)
28
28
  @scope.tap do |s|
29
- s.where_values += s.send(:build_where, opts, *rest).map do |r|
30
- if r.right.is_a?(Array)
31
- nodes = r.right.map { |expr| node_type.new(r.left, expr) }
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 = if s.respond_to?(:where_clause_factory, true)
35
+ # ActiveRecord 5.0 to 6.0
36
+ s.send(:where_clause_factory).build({key => value}, rest)
37
+ else
38
+ # ActiveRecord 6.1, maybe higher
39
+ s.send(:build_where_clause, {key => value}, rest)
40
+ end
41
+ equal_where_clause_predicate = equal_where_clause.send(:predicates).first
42
+
43
+ new_predicate = if equal_where_clause_predicate.right.is_a?(Array)
44
+ nodes = equal_where_clause_predicate.right.map do |expr|
45
+ node_type.new(equal_where_clause_predicate.left, expr)
46
+ end
32
47
  Arel::Nodes::Grouping.new block.call(nodes)
33
48
  else
34
- node_type.new(r.left, r.right)
49
+ node_type.new(equal_where_clause_predicate.left, equal_where_clause_predicate.right)
35
50
  end
51
+
52
+ # Passing `Arel::Nodes::Node` into `where_clause_factory`
53
+ # Will lose the binding values since 5.1
54
+ # due to this PR
55
+ # https://github.com/rails/rails/pull/26073
56
+ new_where_clause = if equal_where_clause.respond_to?(:binds)
57
+ Relation::WhereClause.new([new_predicate], equal_where_clause.binds)
58
+ else
59
+ Relation::WhereClause.new([new_predicate])
60
+ end
61
+
62
+ s.where_clause += new_where_clause
36
63
  end
37
64
  end
38
65
  end
@@ -40,4 +67,8 @@ module ActiveRecord
40
67
  end
41
68
  end
42
69
 
43
- ActiveRecord::QueryMethods::WhereChain.send(:include, ActiveRecord::QueryMethods::Like)
70
+ ActiveSupport.on_load(:active_record) do
71
+ ActiveRecord.eager_load!
72
+
73
+ ActiveRecord::QueryMethods::WhereChain.send(:include, ::ActiveRecord::Like::WhereChainExtensions)
74
+ end
data/test/helper.rb CHANGED
@@ -92,9 +92,7 @@ else
92
92
  include Test::SQLite3
93
93
  end
94
94
 
95
- unless ENV['TRAVIS'] # if we're running on Travis, no drop/create needed
96
- drop_and_create_database
97
- end
95
+ drop_and_create_database
98
96
 
99
97
  connect_db
100
98
 
@@ -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.where_values.first.must_be_instance_of(Arel::Nodes::Matches)
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,24 @@ describe ActiveRecord::QueryMethods::WhereChain do
13
13
  @attribute = "title"
14
14
  @value = '%value%'
15
15
 
16
- @relation_specifier = Post.where.like(@attribute => @value).where_values.first
16
+ @relation = Post.where.like(@attribute => @value)
17
+ @first_predicate = @relation.where_clause.send(:predicates).first
17
18
  end
18
19
 
19
20
  it "has the attribute as the left operand" do
20
- @relation_specifier.left.name.must_equal @attribute
21
+ @first_predicate.left.name.must_equal @attribute
22
+ end
23
+
24
+ it "has the value as the right operand" do
25
+ # Rails 5.0 & 5.1
26
+ first_bind = if @relation.where_clause.respond_to?(:binds)
27
+ @relation.where_clause.send(:binds).first
28
+ else
29
+ # Rails 5.2
30
+ @first_predicate.right.value
31
+ end
32
+
33
+ first_bind.value.must_equal @value
21
34
  end
22
35
  end
23
36
  end
@@ -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.where_values.first.must_be_instance_of(Arel::Nodes::DoesNotMatch)
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,25 @@ describe ActiveRecord::QueryMethods::WhereChain do
13
13
  @attribute = "title"
14
14
  @value = '%value%'
15
15
 
16
- @relation_specifier = Post.where.not_like(@attribute => @value).where_values.first
16
+ @relation = Post.where.like(@attribute => @value)
17
+ @first_predicate = @relation.where_clause.send(:predicates).first
17
18
  end
18
19
 
19
20
  it "has the attribute as the left operand" do
20
- @relation_specifier.left.name.must_equal @attribute
21
+ @first_predicate.left.name.must_equal @attribute
22
+ end
23
+
24
+ it "has the value as the right operand" do
25
+ # Rails 5.0 & 5.1
26
+ first_bind = if @relation.where_clause.respond_to?(:binds)
27
+ @relation.where_clause.send(:binds).first
28
+ else
29
+ # Rails 5.2
30
+ @first_predicate.right.value
31
+ end
32
+
33
+ first_bind.value.must_equal @value
21
34
  end
22
35
  end
23
36
  end
24
37
  end
25
-
metadata CHANGED
@@ -1,29 +1,119 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-like
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 6.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - René van den Berg
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-10 00:00:00.000000000 Z
11
+ date: 2022-01-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '6.0'
17
20
  - - ">="
18
21
  - !ruby/object:Gem::Version
19
- version: 4.0.0
22
+ version: 6.0.0
20
23
  type: :runtime
21
24
  prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '6.0'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 6.0.0
33
+ - !ruby/object:Gem::Dependency
34
+ name: pg
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: mysql2
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ - !ruby/object:Gem::Dependency
62
+ name: sqlite3
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ - !ruby/object:Gem::Dependency
76
+ name: rake
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ - !ruby/object:Gem::Dependency
90
+ name: minitest
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '3'
96
+ type: :development
97
+ prerelease: false
22
98
  version_requirements: !ruby/object:Gem::Requirement
23
99
  requirements:
24
100
  - - ">="
25
101
  - !ruby/object:Gem::Version
26
- version: 4.0.0
102
+ version: '3'
103
+ - !ruby/object:Gem::Dependency
104
+ name: appraisal
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - "~>"
108
+ - !ruby/object:Gem::Version
109
+ version: '2.0'
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - "~>"
115
+ - !ruby/object:Gem::Version
116
+ version: '2.0'
27
117
  description: An ActiveRecord plugin providing a higher-level abstraction for SQL 'LIKE'
28
118
  queries
29
119
  email:
@@ -34,11 +124,14 @@ extra_rdoc_files: []
34
124
  files:
35
125
  - ".gitignore"
36
126
  - ".travis.yml"
127
+ - Appraisals
37
128
  - Gemfile
38
129
  - LICENSE.txt
39
130
  - README.md
40
131
  - Rakefile
41
132
  - activerecord-like.gemspec
133
+ - gemfiles/rails_6_0.gemfile
134
+ - gemfiles/rails_6_1.gemfile
42
135
  - lib/active_record/like.rb
43
136
  - lib/active_record/like/version.rb
44
137
  - lib/activerecord-like.rb
@@ -50,7 +143,7 @@ files:
50
143
  homepage: http://github.com/ReneB/activerecord-like
51
144
  licenses: []
52
145
  metadata: {}
53
- post_install_message:
146
+ post_install_message:
54
147
  rdoc_options: []
55
148
  require_paths:
56
149
  - lib
@@ -65,9 +158,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
65
158
  - !ruby/object:Gem::Version
66
159
  version: '0'
67
160
  requirements: []
68
- rubyforge_project:
69
- rubygems_version: 2.4.6
70
- signing_key:
161
+ rubygems_version: 3.2.3
162
+ signing_key:
71
163
  specification_version: 4
72
164
  summary: 'ActiveRecord::Like provides ActiveRecord::Base with where.like(attribute:
73
165
  string)-style extensions. This functionality was, at one point, included in Rails-master,