diff --git a/lib/jquery-rjs.rb b/lib/jquery-rjs.rb index fee2a42..b5cd478 100644 --- a/lib/jquery-rjs.rb +++ b/lib/jquery-rjs.rb @@ -6,6 +6,11 @@ end module JqueryRjs + def use_alias_method_chain? + @use_alias_method_chain ||= RUBY_VERSION < '2' + end + module_function :use_alias_method_chain? + class Engine < Rails::Engine initializer 'jquery-rjs.initialize' do ActiveSupport.on_load(:action_controller) do diff --git a/lib/jquery-rjs/rendering.rb b/lib/jquery-rjs/rendering.rb index 9523db9..d1ba04c 100644 --- a/lib/jquery-rjs/rendering.rb +++ b/lib/jquery-rjs/rendering.rb @@ -1,19 +1,19 @@ require 'action_view/helpers/rendering_helper' module JqueryRjs::RenderingHelper - method_name = "render#{'_with_update' if RUBY_VERSION < '2'}" + method_name = "render#{'_with_update' if JqueryRjs.use_alias_method_chain?}" define_method(method_name) do |options = {}, locals = {}, &block| if options == :update update_page(&block) else args = options, locals, block - RUBY_VERSION < '2' ? render_without_update(*args) : super(*args) + JqueryRjs.use_alias_method_chain? ? render_without_update(*args) : super(*args) end end end -if RUBY_VERSION < '2' +if JqueryRjs.use_alias_method_chain? ActionView::Helpers::RenderingHelper.module_eval do include JqueryRjs::RenderingHelper alias_method_chain :render, :update diff --git a/lib/jquery-rjs/selector_assertions.rb b/lib/jquery-rjs/selector_assertions.rb index 920fd1d..2995408 100644 --- a/lib/jquery-rjs/selector_assertions.rb +++ b/lib/jquery-rjs/selector_assertions.rb @@ -197,7 +197,7 @@ def response_from_page # +assert_select+ and +css_select+ call this to obtain the content in the HTML # page, or from all the RJS statements, depending on the type of response. - define_method("response_from_page#{'_with_rjs' if RUBY_VERSION < '2'}") do + define_method("response_from_page#{'_with_rjs' if JqueryRjs.use_alias_method_chain?}") do content_type = @response.content_type if content_type && Mime[:js] =~ content_type @@ -216,7 +216,7 @@ def response_from_page root else - RUBY_VERSION < '2' ? response_from_page_without_rjs : super() + JqueryRjs.use_alias_method_chain? ? response_from_page_without_rjs : super() end end @@ -240,7 +240,7 @@ def unescape_rjs(rjs_string) Rails::Dom::Testing::Assertions::SelectorAssertions end -if RUBY_VERSION < '2' +if JqueryRjs.use_alias_method_chain? module_to_patch.module_eval do include JqueryRjs::SelectorAssertions alias_method_chain :response_from_page, :rjs