Drop Rails 6.0 support

This commit is contained in:
David Rodríguez 2022-05-06 09:23:48 +02:00
parent a72f59764e
commit e1ddee7477
No known key found for this signature in database
GPG Key ID: 1008A258BB37309C
11 changed files with 27 additions and 157 deletions

View File

@ -13,7 +13,6 @@ jobs:
rails:
- v7.0.2
- v6.1.5
- v6.0.4
ruby:
- 3.1.1
- 3.0.2
@ -40,7 +39,6 @@ jobs:
rails:
- v7.0.2
- v6.1.5
- v6.0.4
ruby:
- 3.1.1
- 3.0.2
@ -76,7 +74,6 @@ jobs:
rails:
- v7.0.2
- v6.1.5
- v6.0.4
ruby:
- 3.1.1
- 3.0.2

View File

@ -64,7 +64,7 @@ Here's a quick guide:
2. Create a thoughtfully-named branch for your changes (`git checkout -b my-new-feature`).
3. Install the development dependencies by running `bundle install`.
To install rails other than latest (set in Gemfile): `RAILS='6-0-stable' bundle install`
To install rails other than latest (set in Gemfile): `RAILS='6-1-stable' bundle install`
4. Begin by running the tests. We only take pull requests with passing tests,
and it's great to know that you have a clean slate:

View File

@ -3,7 +3,7 @@ gemspec
gem 'rake'
rails = ENV['RAILS'] || '6-0-stable'
rails = ENV['RAILS'] || '6-1-stable'
rails_version = case rails
when /\// # A path
@ -15,7 +15,7 @@ rails_version = case rails
end
gem 'faker', '~> 2.0'
gem 'sqlite3', ::Gem::Version.new(rails_version == 'main' ? '6.2.0.alpha' : rails_version) >= ::Gem::Version.new('6-0-stable') ? '~> 1.4.1' : '~> 1.3.3'
gem 'sqlite3', '~> 1.4.1'
gem 'pg', '~> 1.0'
gem 'pry', '~> 0.12.2'
gem 'byebug'

View File

@ -1,20 +0,0 @@
module Polyamorous
module JoinAssociationExtensions
include SwappingReflectionClass
def self.prepended(base)
base.class_eval { attr_reader :join_type }
end
def initialize(reflection, children, polymorphic_class = nil, join_type = Arel::Nodes::InnerJoin)
@join_type = join_type
if polymorphic_class && ::ActiveRecord::Base > polymorphic_class
swapping_reflection_klass(reflection, polymorphic_class) do |reflection|
super(reflection, children)
self.reflection.options[:polymorphic] = true
end
else
super(reflection, children)
end
end
end
end

View File

@ -1,79 +0,0 @@
module Polyamorous
module JoinDependencyExtensions
# Replaces ActiveRecord::Associations::JoinDependency#build
def build(associations, base_klass)
associations.map do |name, right|
if name.is_a? Join
reflection = find_reflection base_klass, name.name
reflection.check_validity!
reflection.check_eager_loadable!
klass = if reflection.polymorphic?
name.klass || base_klass
else
reflection.klass
end
JoinAssociation.new(reflection, build(right, klass), name.klass, name.type)
else
reflection = find_reflection base_klass, name
reflection.check_validity!
reflection.check_eager_loadable!
if reflection.polymorphic?
raise ActiveRecord::EagerLoadPolymorphicError.new(reflection)
end
JoinAssociation.new(reflection, build(right, reflection.klass))
end
end
end
def join_constraints(joins_to_add, alias_tracker)
@alias_tracker = alias_tracker
construct_tables!(join_root)
joins = make_join_constraints(join_root, join_type)
joins.concat joins_to_add.flat_map { |oj|
construct_tables!(oj.join_root)
if join_root.match?(oj.join_root) && join_root.table.name == oj.join_root.table.name
walk join_root, oj.join_root, oj.join_type
else
make_join_constraints(oj.join_root, oj.join_type)
end
}
end
private
def make_constraints(parent, child, join_type = Arel::Nodes::OuterJoin)
foreign_table = parent.table
foreign_klass = parent.base_klass
join_type = child.join_type || join_type if join_type == Arel::Nodes::InnerJoin
joins = child.join_constraints(foreign_table, foreign_klass, join_type, alias_tracker)
joins.concat child.children.flat_map { |c| make_constraints(child, c, join_type) }
end
module ClassMethods
# Prepended before ActiveRecord::Associations::JoinDependency#walk_tree
#
def walk_tree(associations, hash)
case associations
when TreeNode
associations.add_to_tree(hash)
when Hash
associations.each do |k, v|
cache =
if TreeNode === k
k.add_to_tree(hash)
else
hash[k] ||= {}
end
walk_tree(v, cache)
end
else
super(associations, hash)
end
end
end
end
end

View File

@ -1,11 +0,0 @@
module Polyamorous
module ReflectionExtensions
def join_scope(table, foreign_table, foreign_klass)
if respond_to?(:polymorphic?) && polymorphic?
super.where!(foreign_table[foreign_type].eq(klass.name))
else
super
end
end
end
end

View File

@ -1 +1,11 @@
require 'polyamorous/activerecord_6.0_ruby_2/reflection'
module Polyamorous
module ReflectionExtensions
def join_scope(table, foreign_table, foreign_klass)
if respond_to?(:polymorphic?) && polymorphic?
super.where!(foreign_table[foreign_type].eq(klass.name))
else
super
end
end
end
end

View File

@ -110,11 +110,7 @@ module Ransack
def join_sources
base, joins = begin
alias_tracker = ::ActiveRecord::Associations::AliasTracker.create(self.klass.connection, @object.table.name, [])
constraints = if ::Gem::Version.new(::ActiveRecord::VERSION::STRING) >= ::Gem::Version.new(Constants::RAILS_6_1)
@join_dependency.join_constraints(@object.joins_values, alias_tracker, @object.references_values)
else
@join_dependency.join_constraints(@object.joins_values, alias_tracker)
end
constraints = @join_dependency.join_constraints(@object.joins_values, alias_tracker, @object.references_values)
[
Arel::SelectManager.new(@object.table),
@ -324,11 +320,7 @@ module Ransack
@join_dependency.instance_variable_get(:@join_root).children.push found_association
# Builds the arel nodes properly for this association
if ::Gem::Version.new(::ActiveRecord::VERSION::STRING) >= ::Gem::Version.new(Constants::RAILS_6_1)
@tables_pot[found_association] = @join_dependency.construct_tables_for_association!(jd.instance_variable_get(:@join_root), found_association)
else
@join_dependency.send(:construct_tables!, jd.instance_variable_get(:@join_root))
end
@tables_pot[found_association] = @join_dependency.construct_tables_for_association!(jd.instance_variable_get(:@join_root), found_association)
# Leverage the stashed association functionality in AR
@object = @object.joins(jd)
@ -338,22 +330,13 @@ module Ransack
def extract_joins(association)
parent = @join_dependency.instance_variable_get(:@join_root)
reflection = association.reflection
join_constraints = if ::Gem::Version.new(::ActiveRecord::VERSION::STRING) >= ::Gem::Version.new(Constants::RAILS_6_1)
association.join_constraints_with_tables(
parent.table,
parent.base_klass,
Arel::Nodes::OuterJoin,
@join_dependency.instance_variable_get(:@alias_tracker),
@tables_pot[association]
)
else
association.join_constraints(
parent.table,
parent.base_klass,
Arel::Nodes::OuterJoin,
@join_dependency.instance_variable_get(:@alias_tracker)
)
end
join_constraints = association.join_constraints_with_tables(
parent.table,
parent.base_klass,
Arel::Nodes::OuterJoin,
@join_dependency.instance_variable_get(:@alias_tracker),
@tables_pot[association]
)
join_constraints.to_a.flatten
end
end

View File

@ -47,19 +47,11 @@ module Ransack
end
def casted_array?(predicate)
value_from(predicate).is_a?(Array) && predicate.is_a?(Arel::Nodes::Casted)
end
def value_from(predicate)
if predicate.respond_to?(:value)
predicate.value # Rails 6.1
else
predicate.val
end
predicate.value.is_a?(Array) && predicate.is_a?(Arel::Nodes::Casted)
end
def format_values_for(predicate)
value_from(predicate).map do |val|
predicate.value.map do |val|
val.is_a?(String) ? Arel::Nodes.build_quoted(val) : val
end
end

View File

@ -45,8 +45,6 @@ module Ransack
NOT_EQ_ALL = 'not_eq_all'.freeze
CONT = 'cont'.freeze
RAILS_6_1 = '6.1.0'.freeze
RANSACK_SLASH_SEARCHES = 'ransack/searches'.freeze
RANSACK_SLASH_SEARCHES_SLASH_SEARCH = 'ransack/searches/search'.freeze
end

View File

@ -15,8 +15,8 @@ Gem::Specification.new do |s|
s.required_ruby_version = '>= 2.7'
s.license = 'MIT'
s.add_dependency 'activerecord', '>= 6.0.4'
s.add_dependency 'activesupport', '>= 6.0.4'
s.add_dependency 'activerecord', '>= 6.1.5'
s.add_dependency 'activesupport', '>= 6.1.5'
s.add_dependency 'i18n'
s.files = `git ls-files`.split("\n")