baby_squeel 2.0.0 → 4.0.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e317da76921bc04f342b3cd1f219fa6585f642c4b96e936a18a442a1eb51c18b
4
- data.tar.gz: 6a25d3d64d518f5b43124b4dd9083636f10ac0fad1e0ba4e9634f0dded17cb23
3
+ metadata.gz: 8d571146af43e191254a5673d5486af29b31a8762f3f169075cef91ff50bdb09
4
+ data.tar.gz: aedddf1851a4507025d7b291db17c7dcee4ac93c2c66a44f289db031b1872afb
5
5
  SHA512:
6
- metadata.gz: f1bcaadbb4fc5894a5cd1e4c797ac3d6cfbbaee0cad994caf360fc2ac347f9a30019c297bcd254cae7642574b56bd22d927ea492bad76be02905379847af5330
7
- data.tar.gz: 012e06a95f564e7502a4aa73a5629969f82e76a4abf475fa7364f25891f3345710334848313d6c3fc4c3842da29c5fc3220d95d58a1829258445886be8ac143e
6
+ metadata.gz: 18d9b7499e8e3b1e0d9f015e6dc2ca1bf89e35d7ca161a9c29a8b0979e57d142698b66d428d27a9f791a2d29c8275352f1b30d6a784d893e183e204d7c006062
7
+ data.tar.gz: 07c5c306ca8b90756234cecd9ac1eb2463c959ac4e5caedd91fd38e5bf8cb356c6ab438819400c247a7f799a1802d3a93109c43b6804e27a3f68c66a41526827
data/CHANGELOG.md CHANGED
@@ -1,5 +1,26 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [4.0.0] - 2024-11-29
4
+
5
+ - Remove ActiveRecord boundary
6
+ - Added support for ActiveRecord 8.1
7
+ - Added support for Ransack 4.4 (#134)
8
+ - Added support for ActiveRecord 8.0
9
+ - Added support for ActiveRecord 7.2
10
+ - Droped support for ActiveRecord 6.1 and 7.0
11
+ - Added Ruby 3.3 and 3.4 to test matrix
12
+ - Droped support for Ruby 3.0 and 3.1
13
+
14
+ ## [3.0.0] - 2023-11-20
15
+
16
+ - Added support for ActiveRecord 7.1 (#125)
17
+ - Added support for Ruby 3.2 (#128)
18
+ - Updated ransack to 4.1. (#126)
19
+ - Droped support for Ruby 2.6 and 2.7. (#126)
20
+ - Droped support for ActiveRecord 6.0. (#126)
21
+
22
+ ## [2.0.0] - 2022-08-28
23
+
3
24
  - AR 6.1: fix - FrozenError: can't modify frozen object: []
4
25
  - Drop support for ActiveRecord older than 6.0.
5
26
 
@@ -234,7 +255,10 @@
234
255
 
235
256
  - Initial support for selects, orders, wheres, and joins.
236
257
 
237
- [unreleased]: https://github.com/rzane/baby_squeel/compare/v1.4.4...HEAD
258
+ [unreleased]: https://github.com/rzane/baby_squeel/compare/v4.0.0...HEAD
259
+ [4.0.0]: https://github.com/rzane/baby_squeel/compare/v3.0.0...v4.0.0
260
+ [3.0.0]: https://github.com/rzane/baby_squeel/compare/v2.0.0...v3.0.0
261
+ [2.0.0]: https://github.com/rzane/baby_squeel/compare/v1.4.4...v2.0.0
238
262
  [1.4.4]: https://github.com/rzane/baby_squeel/compare/v1.4.3...v1.4.4
239
263
  [1.4.3]: https://github.com/rzane/baby_squeel/compare/v1.4.2...v1.4.3
240
264
  [1.4.2]: https://github.com/rzane/baby_squeel/compare/v1.4.1...v1.4.2
data/ISSUE_TEMPLATE.md CHANGED
@@ -11,7 +11,7 @@ require 'minitest/autorun'
11
11
 
12
12
  gemfile true do
13
13
  source 'https://rubygems.org'
14
- gem 'activerecord', '~> 6.0.0' # which Active Record version?
14
+ gem 'activerecord', '~> 7.1.5' # which Active Record version?
15
15
  gem 'sqlite3'
16
16
  gem 'baby_squeel', github: 'rzane/baby_squeel'
17
17
  end
data/README.md CHANGED
@@ -329,12 +329,30 @@ Check out the [migration guide](https://github.com/rzane/baby_squeel/wiki/Migrat
329
329
 
330
330
  ## Development
331
331
 
332
- 1. Pick an Active Record version to develop against, then export it: `export AR=6.1.4`.
332
+ 1. Pick an Active Record version to develop against, then export it: `export AR=7.2.2`.
333
333
  2. Run `bin/setup` to install dependencies.
334
334
  3. Run `rake` to run the specs.
335
335
 
336
+ One-liner to run the specs with different rails versions:
337
+
338
+ ```
339
+ export AR='~> 7.1.6'; rm Gemfile.lock; bin/setup; rake
340
+ export AR='~> 7.2.3'; rm Gemfile.lock; bin/setup; rake
341
+ export AR='~> 8.0.4'; rm Gemfile.lock; bin/setup; rake
342
+ export AR='~> 8.1.1'; rm Gemfile.lock; bin/setup; rake
343
+ ```
344
+
336
345
  You can also run `bin/console` to open up a prompt where you'll have access to some models to experiment with.
337
346
 
347
+ ## Rails update
348
+
349
+ 1. Update [baby_squeel.gemspec](baby_squeel.gemspec)
350
+ 2. Add the version to test matrix [build.yml](.github/workflows/build.yml)
351
+ 3. Update development section in the [README.md](README.md)
352
+ 4. If you need to change the code consider to add a version check methode in [version_helper.rb](lib/baby_squeel/active_record/version_helper.rb)
353
+ 5. Run the specs with all supported versions
354
+ 6. Add comment to the unreleased section in [CHANGELOG.md](CHANGELOG.md)
355
+
338
356
  ## Contributing
339
357
 
340
358
  Bug reports and pull requests are welcome on GitHub at https://github.com/rzane/baby_squeel.
data/baby_squeel.gemspec CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ['Ray Zane']
10
10
  spec.email = ['ray@promptworks.com']
11
11
 
12
- spec.summary = 'An expressive query DSL for Active Record 4 and 5.'
12
+ spec.summary = 'An expressive query DSL for Active Record 7.1+'
13
13
  spec.description = spec.summary
14
14
  spec.homepage = 'https://github.com/rzane/baby_squeel'
15
15
  spec.license = 'MIT'
@@ -19,8 +19,8 @@ Gem::Specification.new do |spec|
19
19
 
20
20
  spec.files = Dir.glob('{lib/**/*,*.{md,txt,gemspec}}')
21
21
 
22
- spec.add_dependency 'activerecord', '>= 6.0', '< 7.1'
23
- spec.add_dependency 'ransack', '~> 2.3'
22
+ spec.add_dependency 'activerecord', '>= 7.1.5'
23
+ spec.add_dependency 'ransack', '~> 4.1'
24
24
 
25
25
  spec.add_development_dependency 'bundler', '~> 2'
26
26
  spec.add_development_dependency 'rake', '~> 13.0'
@@ -28,7 +28,7 @@ module BabySqueel
28
28
  maximum Calculation.new(DSL.evaluate(self, &block))
29
29
  end
30
30
 
31
- private
31
+ protected
32
32
 
33
33
  # @override
34
34
  def aggregate_column(column_name)
@@ -1,6 +1,5 @@
1
1
  require 'baby_squeel/dsl'
2
2
  require 'baby_squeel/join_dependency'
3
- require 'baby_squeel/active_record/version_helper'
4
3
 
5
4
  module BabySqueel
6
5
  module ActiveRecord
@@ -51,34 +50,22 @@ module BabySqueel
51
50
  having DSL.evaluate(self, &block)
52
51
  end
53
52
 
54
- if BabySqueel::ActiveRecord::VersionHelper.at_least_6_1?
55
- def construct_join_dependency(associations, join_type)
56
- result = super(associations, join_type)
57
- if associations.any? { |assoc| assoc.is_a?(BabySqueel::Join) }
58
- result.extend(BabySqueel::JoinDependency::Injector6_1)
59
- end
60
- result
53
+ def construct_join_dependency(associations, join_type)
54
+ result = super(associations, join_type)
55
+ if associations.any? { |assoc| assoc.is_a?(BabySqueel::Join) }
56
+ result.extend(BabySqueel::JoinDependency::Injector6_1)
61
57
  end
58
+ result
59
+ end
62
60
 
63
- private
64
-
65
- # https://github.com/rails/rails/commit/c0c53ee9d28134757cf1418521cb97c4a135f140
66
- def select_association_list(*args)
67
- if args[0].any? { |join| join.is_a?(BabySqueel::Join) }
68
- args[0].extend(BabySqueel::ActiveRecord::QueryMethods::Injector6_1)
69
- end
70
- super *args
71
- end
72
- else
73
- private
61
+ private
74
62
 
75
- # Active Record will call `each` on the `joins`. The
76
- # Injector has a custom `each` method that handles
77
- # BabySqueel::Join nodes.
78
- def build_joins(*args)
79
- args[1] = BabySqueel::JoinDependency::Injector6_0.new(args.second)
80
- super(*args)
63
+ # https://github.com/rails/rails/commit/c0c53ee9d28134757cf1418521cb97c4a135f140
64
+ def select_association_list(*args)
65
+ if args[0].any? { |join| join.is_a?(BabySqueel::Join) }
66
+ args[0].extend(BabySqueel::ActiveRecord::QueryMethods::Injector6_1)
81
67
  end
68
+ super *args
82
69
  end
83
70
  end
84
71
  end
@@ -3,9 +3,17 @@ require 'baby_squeel/dsl'
3
3
  module BabySqueel
4
4
  module ActiveRecord
5
5
  class VersionHelper
6
- def self.at_least_6_1?
7
- ::ActiveRecord::VERSION::MAJOR > 6 ||
8
- ::ActiveRecord::VERSION::MAJOR == 6 && ::ActiveRecord::VERSION::MINOR >= 1
6
+ # Example
7
+ # BabySqueel::ActiveRecord::VersionHelper.at_least_7_1?
8
+ #
9
+ # def self.at_least_7_1?
10
+ # ::ActiveRecord::VERSION::MAJOR > 7 ||
11
+ # ::ActiveRecord::VERSION::MAJOR == 7 && ::ActiveRecord::VERSION::MINOR >= 1
12
+ # end
13
+
14
+ def self.at_least_7_2?
15
+ ::ActiveRecord::VERSION::MAJOR > 7 ||
16
+ ::ActiveRecord::VERSION::MAJOR == 7 && ::ActiveRecord::VERSION::MINOR >= 2
9
17
  end
10
18
  end
11
19
  end
@@ -1,5 +1,4 @@
1
1
  require 'baby_squeel/relation'
2
- require 'baby_squeel/active_record/version_helper'
3
2
 
4
3
  module BabySqueel
5
4
  class Association < Relation
@@ -100,13 +99,7 @@ module BabySqueel
100
99
  def build_where_clause(other)
101
100
  if valid_where_clause?(other)
102
101
  relation = @parent._scope.all
103
-
104
- if BabySqueel::ActiveRecord::VersionHelper.at_least_6_1?
105
- relation.send(:build_where_clause, { _reflection.name => other }, [])
106
- else
107
- factory = relation.send(:where_clause_factory)
108
- factory.build({ _reflection.name => other }, [])
109
- end
102
+ relation.send(:build_where_clause, { _reflection.name => other }, [])
110
103
  else
111
104
  raise AssociationComparisonError.new(_reflection.name, other)
112
105
  end
@@ -46,20 +46,13 @@ module BabySqueel
46
46
  # a list (in order of chaining) of associations and finding
47
47
  # the respective JoinAssociation at each level.
48
48
  def find_alias(associations)
49
- if BabySqueel::ActiveRecord::VersionHelper.at_least_6_1?
50
- # construct_tables! got removed by rails
51
- # https://github.com/rails/rails/commit/590b045ee2c0906ff162e6658a184afb201865d7
52
- #
53
- # construct_tables_for_association! is a method from the polyamorous (ransack) gem
54
- join_root = join_dependency.send(:join_root)
55
- join_root.each_children do |parent, child|
56
- join_dependency.construct_tables_for_association!(parent, child)
57
- end
58
- else
59
- # If we tell join_dependency to construct its tables, Active Record
60
- # handles building the correct aliases and attaching them to its
61
- # JoinDepenencies.
62
- join_dependency.send(:construct_tables!, join_dependency.send(:join_root))
49
+ # construct_tables! got removed by rails
50
+ # https://github.com/rails/rails/commit/590b045ee2c0906ff162e6658a184afb201865d7
51
+ #
52
+ # construct_tables_for_association! is a method from the polyamorous (ransack) gem
53
+ join_root = join_dependency.send(:join_root)
54
+ join_root.each_children do |parent, child|
55
+ join_dependency.construct_tables_for_association!(parent, child)
63
56
  end
64
57
 
65
58
  join_association = find_join_association(associations)
@@ -95,7 +88,7 @@ module BabySqueel
95
88
  joins += relation.joins_values
96
89
  joins += relation.left_outer_joins_values
97
90
 
98
- buckets = joins.group_by do |join|
91
+ _buckets = joins.group_by do |join|
99
92
  case join
100
93
  when String
101
94
  :string_join
@@ -126,7 +119,9 @@ module BabySqueel
126
119
 
127
120
  join_list = join_nodes + joins
128
121
 
129
- alias_tracker = Associations::AliasTracker.create(relation.klass.connection, relation.table.name, join_list)
122
+ alias_tracker = Associations::AliasTracker.create(
123
+ BabySqueel::ActiveRecord::VersionHelper.at_least_7_2? ? relation.klass.connection_pool : relation.klass.connection,
124
+ relation.table.name, join_list)
130
125
  join_dependency = Associations::JoinDependency.new(relation.klass, relation.table, association_joins, Arel::Nodes::InnerJoin)
131
126
  join_dependency.instance_variable_set(:@alias_tracker, alias_tracker)
132
127
 
@@ -35,19 +35,8 @@ module BabySqueel
35
35
 
36
36
  private
37
37
 
38
- # NullRelation must be treated as a special case, because
39
- # NullRelation#to_sql returns an empty string. As such,
40
- # we need to convert the NullRelation to regular relation.
41
- # Conveniently, this approach automatically adds a 1=0.
42
- # I have literally no idea why, but I'll take it.
43
38
  def sanitize_relation(rel)
44
- if rel.kind_of? ::ActiveRecord::NullRelation
45
- other = rel.spawn
46
- other.extending_values -= [::ActiveRecord::NullRelation]
47
- sanitize_relation rel.unscoped.merge(other)
48
- else
49
- Arel.sql rel.to_sql
50
- end
39
+ Arel.sql(rel.to_sql)
51
40
  end
52
41
  end
53
42
  end
@@ -2,7 +2,7 @@ module BabySqueel
2
2
  module Nodes
3
3
  # This proxy class allows us to quack like any arel object. When a
4
4
  # method missing is hit, we'll instantiate a new proxy object.
5
- class Proxy < ActiveSupport::ProxyObject
5
+ class Proxy < BasicObject
6
6
  # Resolve constants the normal way
7
7
  def self.const_missing(name)
8
8
  ::Object.const_get(name)
@@ -1,3 +1,3 @@
1
1
  module BabySqueel
2
- VERSION = '2.0.0'.freeze
2
+ VERSION = '4.0.0'.freeze
3
3
  end
data/lib/baby_squeel.rb CHANGED
@@ -1,17 +1,9 @@
1
1
  require 'active_record'
2
2
  require 'active_record/relation'
3
- begin
4
- require 'polyamorous'
5
- rescue LoadError
6
- # Trying loading from 'ransack' as of commit c9cc20de9 (post v2.3.2)
7
- require 'polyamorous/polyamorous'
8
- end
3
+ # Loading polyamorous from 'ransack' as of commit c9cc20de9 (post v2.3.2)
4
+ require 'polyamorous/polyamorous'
9
5
  require 'baby_squeel/version'
10
6
  require 'baby_squeel/errors'
11
- require 'baby_squeel/active_record/base'
12
- require 'baby_squeel/active_record/query_methods'
13
- require 'baby_squeel/active_record/calculations'
14
- require 'baby_squeel/active_record/where_chain'
15
7
 
16
8
  module BabySqueel
17
9
  class << self
@@ -47,6 +39,11 @@ module BabySqueel
47
39
  end
48
40
 
49
41
  ActiveSupport.on_load :active_record do
42
+ require 'baby_squeel/active_record/base'
43
+ require 'baby_squeel/active_record/query_methods'
44
+ require 'baby_squeel/active_record/calculations'
45
+ require 'baby_squeel/active_record/where_chain'
46
+
50
47
  ::ActiveRecord::Base.extend BabySqueel::ActiveRecord::Base
51
48
  ::ActiveRecord::Relation.prepend BabySqueel::ActiveRecord::QueryMethods
52
49
  ::ActiveRecord::Relation.prepend BabySqueel::ActiveRecord::Calculations
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: baby_squeel
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 4.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ray Zane
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2022-08-28 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: activerecord
@@ -16,34 +15,28 @@ dependencies:
16
15
  requirements:
17
16
  - - ">="
18
17
  - !ruby/object:Gem::Version
19
- version: '6.0'
20
- - - "<"
21
- - !ruby/object:Gem::Version
22
- version: '7.1'
18
+ version: 7.1.5
23
19
  type: :runtime
24
20
  prerelease: false
25
21
  version_requirements: !ruby/object:Gem::Requirement
26
22
  requirements:
27
23
  - - ">="
28
24
  - !ruby/object:Gem::Version
29
- version: '6.0'
30
- - - "<"
31
- - !ruby/object:Gem::Version
32
- version: '7.1'
25
+ version: 7.1.5
33
26
  - !ruby/object:Gem::Dependency
34
27
  name: ransack
35
28
  requirement: !ruby/object:Gem::Requirement
36
29
  requirements:
37
30
  - - "~>"
38
31
  - !ruby/object:Gem::Version
39
- version: '2.3'
32
+ version: '4.1'
40
33
  type: :runtime
41
34
  prerelease: false
42
35
  version_requirements: !ruby/object:Gem::Requirement
43
36
  requirements:
44
37
  - - "~>"
45
38
  - !ruby/object:Gem::Version
46
- version: '2.3'
39
+ version: '4.1'
47
40
  - !ruby/object:Gem::Dependency
48
41
  name: bundler
49
42
  requirement: !ruby/object:Gem::Requirement
@@ -100,7 +93,7 @@ dependencies:
100
93
  - - ">="
101
94
  - !ruby/object:Gem::Version
102
95
  version: '0'
103
- description: An expressive query DSL for Active Record 4 and 5.
96
+ description: An expressive query DSL for Active Record 7.1+
104
97
  email:
105
98
  - ray@promptworks.com
106
99
  executables: []
@@ -141,7 +134,6 @@ homepage: https://github.com/rzane/baby_squeel
141
134
  licenses:
142
135
  - MIT
143
136
  metadata: {}
144
- post_install_message:
145
137
  rdoc_options: []
146
138
  require_paths:
147
139
  - lib
@@ -156,8 +148,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
156
148
  - !ruby/object:Gem::Version
157
149
  version: '0'
158
150
  requirements: []
159
- rubygems_version: 3.3.7
160
- signing_key:
151
+ rubygems_version: 3.6.9
161
152
  specification_version: 4
162
- summary: An expressive query DSL for Active Record 4 and 5.
153
+ summary: An expressive query DSL for Active Record 7.1+
163
154
  test_files: []