From 9330e1686b6f8eeb6549598f29f35987db26fdb8 Mon Sep 17 00:00:00 2001 From: James Le Cuirot Date: Wed, 26 Nov 2014 12:35:34 +0000 Subject: [PATCH] Fix 4.1 adapter under Rubinius Calling return inside a block under Rubinius results in a LocalJumpError, at least with version 2.3.0. This is probably a Rubinius bug but it is easy enough to work around it here. --- .../active_record/4.1/relation_extensions.rb | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/squeel/adapters/active_record/4.1/relation_extensions.rb b/lib/squeel/adapters/active_record/4.1/relation_extensions.rb index 2850d8e..591a5d9 100644 --- a/lib/squeel/adapters/active_record/4.1/relation_extensions.rb +++ b/lib/squeel/adapters/active_record/4.1/relation_extensions.rb @@ -168,18 +168,23 @@ def build_join_dependency(manager, joins) %w(where having group order).each do |visitor| define_method "#{visitor}_visit" do |values| join_dependencies = [join_dependency] + stashed_join_dependencies - join_dependencies.each do |jd| + result = join_dependencies.find do |jd| context = Adapters::ActiveRecord::Context.new(jd) begin - return Visitors.const_get("#{visitor.capitalize}Visitor").new(context).accept!(values) + # Don't use return here, it breaks Rubinius 2.3.0. + break Visitors.const_get("#{visitor.capitalize}Visitor").new(context).accept!(values) rescue Adapters::ActiveRecord::Context::NoParentFoundError => e next end end - # Fail Safe, call the normal accept method. - context = Adapters::ActiveRecord::Context.new(join_dependency) - Visitors.const_get("#{visitor.capitalize}Visitor").new(context).accept(values) + if result.nil? + # Fail Safe, call the normal accept method. + context = Adapters::ActiveRecord::Context.new(join_dependency) + Visitors.const_get("#{visitor.capitalize}Visitor").new(context).accept(values) + else + result + end end end