From 07d8f46b85b08187cabd477cc3ca37f2c818e9aa Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Tue, 13 Mar 2007 02:14:31 +0000 Subject: Consistent public/protected/private visibility for chained methods. Closes #7813. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6396 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/lib/action_controller/benchmarking.rb | 60 ++++++++++++------------ actionpack/lib/action_controller/filters.rb | 20 ++++---- actionpack/lib/action_controller/flash.rb | 32 +++++++------ actionpack/lib/action_controller/layout.rb | 39 +++++++-------- 4 files changed, 78 insertions(+), 73 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_controller/benchmarking.rb b/actionpack/lib/action_controller/benchmarking.rb index 469976e532..8e0d83c2d6 100644 --- a/actionpack/lib/action_controller/benchmarking.rb +++ b/actionpack/lib/action_controller/benchmarking.rb @@ -40,44 +40,44 @@ module ActionController #:nodoc: end end - def render_with_benchmark(options = nil, deprecated_status = nil, &block) - unless logger - render_without_benchmark(options, deprecated_status, &block) - else - db_runtime = ActiveRecord::Base.connection.reset_runtime if Object.const_defined?("ActiveRecord") && ActiveRecord::Base.connected? + protected + def render_with_benchmark(options = nil, deprecated_status = nil, &block) + unless logger + render_without_benchmark(options, deprecated_status, &block) + else + db_runtime = ActiveRecord::Base.connection.reset_runtime if Object.const_defined?("ActiveRecord") && ActiveRecord::Base.connected? - render_output = nil - @rendering_runtime = Benchmark::measure{ render_output = render_without_benchmark(options, deprecated_status, &block) }.real + render_output = nil + @rendering_runtime = Benchmark::measure{ render_output = render_without_benchmark(options, deprecated_status, &block) }.real - if Object.const_defined?("ActiveRecord") && ActiveRecord::Base.connected? - @db_rt_before_render = db_runtime - @db_rt_after_render = ActiveRecord::Base.connection.reset_runtime - @rendering_runtime -= @db_rt_after_render - end + if Object.const_defined?("ActiveRecord") && ActiveRecord::Base.connected? + @db_rt_before_render = db_runtime + @db_rt_after_render = ActiveRecord::Base.connection.reset_runtime + @rendering_runtime -= @db_rt_after_render + end - render_output - end - end + render_output + end + end - def perform_action_with_benchmark - unless logger - perform_action_without_benchmark - else - runtime = [ Benchmark::measure{ perform_action_without_benchmark }.real, 0.0001 ].max + private + def perform_action_with_benchmark + unless logger + perform_action_without_benchmark + else + runtime = [ Benchmark::measure{ perform_action_without_benchmark }.real, 0.0001 ].max - log_message = "Completed in #{sprintf("%.5f", runtime)} (#{(1 / runtime).floor} reqs/sec)" - log_message << rendering_runtime(runtime) if defined?(@rendering_runtime) - log_message << active_record_runtime(runtime) if Object.const_defined?("ActiveRecord") && ActiveRecord::Base.connected? - log_message << " | #{headers["Status"]}" - log_message << " [#{complete_request_uri rescue "unknown"}]" + log_message = "Completed in #{sprintf("%.5f", runtime)} (#{(1 / runtime).floor} reqs/sec)" + log_message << rendering_runtime(runtime) if defined?(@rendering_runtime) + log_message << active_record_runtime(runtime) if Object.const_defined?("ActiveRecord") && ActiveRecord::Base.connected? + log_message << " | #{headers["Status"]}" + log_message << " [#{complete_request_uri rescue "unknown"}]" - logger.info(log_message) - response.headers["X-Runtime"] = sprintf("%.5f", runtime) + logger.info(log_message) + response.headers["X-Runtime"] = sprintf("%.5f", runtime) + end end - end - - private def rendering_runtime(runtime) " | Rendering: #{sprintf("%.5f", @rendering_runtime)} (#{sprintf("%d", (@rendering_runtime * 100) / runtime)}%)" end diff --git a/actionpack/lib/action_controller/filters.rb b/actionpack/lib/action_controller/filters.rb index 3290defff8..ec5bb759df 100644 --- a/actionpack/lib/action_controller/filters.rb +++ b/actionpack/lib/action_controller/filters.rb @@ -615,15 +615,6 @@ module ActionController #:nodoc: end end - def perform_action_with_filters - call_filter(self.class.filter_chain, 0) - end - - def process_with_filters(request, response, method = :perform_action, *arguments) #:nodoc: - @before_filter_chain_aborted = false - process_without_filters(request, response, method, *arguments) - end - def filter_chain self.class.filter_chain end @@ -654,7 +645,18 @@ module ActionController #:nodoc: return false end + protected + + def process_with_filters(request, response, method = :perform_action, *arguments) #:nodoc: + @before_filter_chain_aborted = false + process_without_filters(request, response, method, *arguments) + end + private + def perform_action_with_filters + call_filter(self.class.filter_chain, 0) + end + def process_cleanup_with_filters if @before_filter_chain_aborted close_session diff --git a/actionpack/lib/action_controller/flash.rb b/actionpack/lib/action_controller/flash.rb index 0d12503904..2544db2fda 100644 --- a/actionpack/lib/action_controller/flash.rb +++ b/actionpack/lib/action_controller/flash.rb @@ -136,23 +136,14 @@ module ActionController #:nodoc: end module InstanceMethods #:nodoc: - def assign_shortcuts_with_flash(request, response) #:nodoc: - assign_shortcuts_without_flash(request, response) - flash(:refresh) - end - - def process_cleanup_with_flash - flash.sweep if @_session - process_cleanup_without_flash - end - def reset_session_with_flash - reset_session_without_flash - remove_instance_variable(:@_flash) - flash(:refresh) - end + protected + def reset_session_with_flash + reset_session_without_flash + remove_instance_variable(:@_flash) + flash(:refresh) + end - protected # Access the contents of the flash. Use flash["notice"] to read a notice you put there or # flash["notice"] = "hello" to put a new one. # Note that if sessions are disabled only flash.now will work. @@ -177,6 +168,17 @@ module ActionController #:nodoc: ActiveSupport::Deprecation.warn 'keep_flash is deprecated; use flash.keep instead.', caller flash.keep end + + private + def assign_shortcuts_with_flash(request, response) #:nodoc: + assign_shortcuts_without_flash(request, response) + flash(:refresh) + end + + def process_cleanup_with_flash + flash.sweep if @_session + process_cleanup_without_flash + end end end end diff --git a/actionpack/lib/action_controller/layout.rb b/actionpack/lib/action_controller/layout.rb index 115fd7ac18..ca070d0577 100644 --- a/actionpack/lib/action_controller/layout.rb +++ b/actionpack/lib/action_controller/layout.rb @@ -233,31 +233,32 @@ module ActionController #:nodoc: end end - def render_with_a_layout(options = nil, deprecated_status = nil, deprecated_layout = nil, &block) #:nodoc: - template_with_options = options.is_a?(Hash) + protected + def render_with_a_layout(options = nil, deprecated_status = nil, deprecated_layout = nil, &block) #:nodoc: + template_with_options = options.is_a?(Hash) - if apply_layout?(template_with_options, options) && (layout = pick_layout(template_with_options, options, deprecated_layout)) - assert_existence_of_template_file(layout) + if apply_layout?(template_with_options, options) && (layout = pick_layout(template_with_options, options, deprecated_layout)) + assert_existence_of_template_file(layout) - options = options.merge :layout => false if template_with_options - logger.info("Rendering template within #{layout}") if logger + options = options.merge :layout => false if template_with_options + logger.info("Rendering template within #{layout}") if logger - if template_with_options - content_for_layout = render_with_no_layout(options, &block) - deprecated_status = options[:status] || deprecated_status + if template_with_options + content_for_layout = render_with_no_layout(options, &block) + deprecated_status = options[:status] || deprecated_status + else + content_for_layout = render_with_no_layout(options, deprecated_status, &block) + end + + erase_render_results + add_variables_to_assigns + @template.instance_variable_set("@content_for_layout", content_for_layout) + response.layout = layout + render_text(@template.render_file(layout, true), deprecated_status) else - content_for_layout = render_with_no_layout(options, deprecated_status, &block) + render_with_no_layout(options, deprecated_status, &block) end - - erase_render_results - add_variables_to_assigns - @template.instance_variable_set("@content_for_layout", content_for_layout) - response.layout = layout - render_text(@template.render_file(layout, true), deprecated_status) - else - render_with_no_layout(options, deprecated_status, &block) end - end private -- cgit v1.2.3