From 1d18f221fed5cc4d1712b0c70cad23f5e845c1b3 Mon Sep 17 00:00:00 2001 From: fanda Date: Wed, 17 May 2017 21:16:44 +0200 Subject: [PATCH 1/2] Fixes alias_method_chain DEPRECATIONs in Rails 5 --- .../predicate_builder/array_handler.rb | 38 ++++++++++--------- .../active_record/relation/query_methods.rb | 29 ++++++++------ 2 files changed, 39 insertions(+), 28 deletions(-) diff --git a/lib/postgres_ext/active_record/5.0/relation/predicate_builder/array_handler.rb b/lib/postgres_ext/active_record/5.0/relation/predicate_builder/array_handler.rb index e3b341d..67f1090 100644 --- a/lib/postgres_ext/active_record/5.0/relation/predicate_builder/array_handler.rb +++ b/lib/postgres_ext/active_record/5.0/relation/predicate_builder/array_handler.rb @@ -5,27 +5,31 @@ module ActiveRecord class PredicateBuilder - module ArrayHandlerPatch - extend ActiveSupport::Concern - included do - def call_with_feature(attribute, value) - column = case attribute.try(:relation) - when Arel::Nodes::TableAlias, NilClass - else - cache = ActiveRecord::Base.connection.schema_cache - if cache.data_source_exists? attribute.relation.name - cache.columns(attribute.relation.name).detect{ |col| col.name.to_s == attribute.name.to_s } - end + module CallWithFeature + def call(attribute, value) + column = case attribute.try(:relation) + when Arel::Nodes::TableAlias, NilClass + else + cache = ActiveRecord::Base.connection.schema_cache + if cache.data_source_exists? attribute.relation.name + cache.columns(attribute.relation.name).detect{ |col| col.name.to_s == attribute.name.to_s } end - if column && column.respond_to?(:array) && column.array - attribute.eq(value) - else - call_without_feature(attribute, value) - end + end + if column && column.respond_to?(:array) && column.array + attribute.eq(value) + else + super(attribute, value) end + end + end - alias_method_chain(:call, :feature) + + module ArrayHandlerPatch + extend ActiveSupport::Concern + + included do + prepend CallWithFeature end module ClassMethods diff --git a/lib/postgres_ext/active_record/relation/query_methods.rb b/lib/postgres_ext/active_record/relation/query_methods.rb index ec08343..b0cd36d 100644 --- a/lib/postgres_ext/active_record/relation/query_methods.rb +++ b/lib/postgres_ext/active_record/relation/query_methods.rb @@ -1,5 +1,22 @@ module ActiveRecord + + module BuildArelWithExtension + def build_arel + arel = super + + build_with(arel) + + build_rank(arel, rank_value) if rank_value + + arel + end + end + + module QueryMethods + + prepend BuildArelWithExtension + class WhereChain def overlap(opts, *rest) substitute_comparisons(opts, rest, Arel::Nodes::Overlap, 'overlap') @@ -189,16 +206,6 @@ def ranked!(value) self end - def build_arel_with_extensions - arel = build_arel_without_extensions - - build_with(arel) - - build_rank(arel, rank_value) if rank_value - - arel - end - def build_with(arel) with_statements = with_values.flat_map do |with_value| case with_value @@ -255,6 +262,6 @@ def build_rank(arel, rank_window_options) end end - alias_method_chain :build_arel, :extensions end end + From ef9ead73bd4af5136476d03cf0b9f9bf90ed5d9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Ml=C4=8Doch?= Date: Tue, 4 Jul 2017 11:21:41 +0200 Subject: [PATCH 2/2] fixed typo 'cutuff' -> 'cutoff' --- lib/postgres_ext/active_record/relation.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/postgres_ext/active_record/relation.rb b/lib/postgres_ext/active_record/relation.rb index 43e23f3..d176d57 100644 --- a/lib/postgres_ext/active_record/relation.rb +++ b/lib/postgres_ext/active_record/relation.rb @@ -9,7 +9,7 @@ if ar_5_0_version_cutoff require 'postgres_ext/active_record/5.0/relation/predicate_builder/array_handler' -elsif ar_4_2_version_cutuff +elsif ar_4_2_version_cutoff require 'postgres_ext/active_record/relation/predicate_builder/array_handler' else require 'postgres_ext/active_record/4.x/relation/predicate_builder'