Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes alias_method_chain DEPRECATIONs in Rails 5 #1

Open
wants to merge 3 commits into
base: rails-5
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/postgres_ext/active_record/relation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
29 changes: 18 additions & 11 deletions lib/postgres_ext/active_record/relation/query_methods.rb
Original file line number Diff line number Diff line change
@@ -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')
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -255,6 +262,6 @@ def build_rank(arel, rank_window_options)
end
end

alias_method_chain :build_arel, :extensions
end
end