From a72f59764e587d90c6a9601c52edfbd76bfbc1ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Fri, 6 May 2022 09:23:27 +0200 Subject: [PATCH] Cleanup old compatibility code --- lib/ransack/adapters/active_record/context.rb | 33 +++++-------------- .../active_record/ransack/nodes/condition.rb | 4 +-- lib/ransack/constants.rb | 1 - spec/helpers/polyamorous_helper.rb | 10 ++---- 4 files changed, 13 insertions(+), 35 deletions(-) diff --git a/lib/ransack/adapters/active_record/context.rb b/lib/ransack/adapters/active_record/context.rb index 3b2c55a..083131d 100644 --- a/lib/ransack/adapters/active_record/context.rb +++ b/lib/ransack/adapters/active_record/context.rb @@ -112,10 +112,8 @@ module Ransack 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) - elsif ::Gem::Version.new(::ActiveRecord::VERSION::STRING) >= ::Gem::Version.new(Constants::RAILS_6_0) - @join_dependency.join_constraints(@object.joins_values, alias_tracker) else - @join_dependency.join_constraints(@object.joins_values, @join_type, alias_tracker) + @join_dependency.join_constraints(@object.joins_values, alias_tracker) end [ @@ -284,11 +282,7 @@ module Ransack join_list = join_nodes + convert_join_strings_to_ast(relation.table, string_joins) alias_tracker = ::ActiveRecord::Associations::AliasTracker.create(self.klass.connection, relation.table.name, join_list) - join_dependency = if ::Gem::Version.new(::ActiveRecord::VERSION::STRING) >= ::Gem::Version.new(Constants::RAILS_6_0) - Polyamorous::JoinDependency.new(relation.klass, relation.table, association_joins, Arel::Nodes::OuterJoin) - else - Polyamorous::JoinDependency.new(relation.klass, relation.table, association_joins) - end + join_dependency = Polyamorous::JoinDependency.new(relation.klass, relation.table, association_joins, Arel::Nodes::OuterJoin) join_dependency.instance_variable_set(:@alias_tracker, alias_tracker) join_nodes.each do |join| join_dependency.send(:alias_tracker).aliases[join.left.name.downcase] = 1 @@ -315,22 +309,13 @@ module Ransack end def build_association(name, parent = @base, klass = nil) - if ::Gem::Version.new(::ActiveRecord::VERSION::STRING) >= ::Gem::Version.new(Constants::RAILS_6_0) - jd = Polyamorous::JoinDependency.new( - parent.base_klass, - parent.table, - Polyamorous::Join.new(name, @join_type, klass), - @join_type - ) - found_association = jd.instance_variable_get(:@join_root).children.last - else - jd = Polyamorous::JoinDependency.new( - parent.base_klass, - parent.table, - Polyamorous::Join.new(name, @join_type, klass) - ) - found_association = jd.instance_variable_get(:@join_root).children.last - end + jd = Polyamorous::JoinDependency.new( + parent.base_klass, + parent.table, + Polyamorous::Join.new(name, @join_type, klass), + @join_type + ) + found_association = jd.instance_variable_get(:@join_root).children.last @associations_pot[found_association] = parent diff --git a/lib/ransack/adapters/active_record/ransack/nodes/condition.rb b/lib/ransack/adapters/active_record/ransack/nodes/condition.rb index d6e0942..1a5f20e 100644 --- a/lib/ransack/adapters/active_record/ransack/nodes/condition.rb +++ b/lib/ransack/adapters/active_record/ransack/nodes/condition.rb @@ -53,8 +53,8 @@ module Ransack def value_from(predicate) if predicate.respond_to?(:value) predicate.value # Rails 6.1 - elsif predicate.respond_to?(:val) - predicate.val # Rails 6.0 + else + predicate.val end end diff --git a/lib/ransack/constants.rb b/lib/ransack/constants.rb index 3197b9c..431be14 100644 --- a/lib/ransack/constants.rb +++ b/lib/ransack/constants.rb @@ -45,7 +45,6 @@ module Ransack NOT_EQ_ALL = 'not_eq_all'.freeze CONT = 'cont'.freeze - RAILS_6_0 = '6.0.0'.freeze RAILS_6_1 = '6.1.0'.freeze RANSACK_SLASH_SEARCHES = 'ransack/searches'.freeze diff --git a/spec/helpers/polyamorous_helper.rb b/spec/helpers/polyamorous_helper.rb index b35da72..4e4542a 100644 --- a/spec/helpers/polyamorous_helper.rb +++ b/spec/helpers/polyamorous_helper.rb @@ -3,14 +3,8 @@ module PolyamorousHelper Polyamorous::JoinAssociation.new reflection, children, klass end - if ActiveRecord.version >= ::Gem::Version.new("6.0.0.rc1") - def new_join_dependency(klass, associations = {}) - Polyamorous::JoinDependency.new klass, klass.arel_table, associations, Polyamorous::InnerJoin - end - else - def new_join_dependency(klass, associations = {}) - Polyamorous::JoinDependency.new klass, klass.arel_table, associations - end + def new_join_dependency(klass, associations = {}) + Polyamorous::JoinDependency.new klass, klass.arel_table, associations, Polyamorous::InnerJoin end def new_join(name, type = Polyamorous::InnerJoin, klass = nil)