Permalink
Browse files

Lazy load flash access

  • Loading branch information...
1 parent 9a733f6 commit 7c090509994faa19fcbd534aa78324b70b659627 @josh josh committed Dec 16, 2008
Showing with 14 additions and 10 deletions.
  1. +13 −9 actionpack/lib/action_controller/flash.rb
  2. +1 −1 actionpack/lib/action_controller/test_process.rb
@@ -27,8 +27,8 @@ module Flash
def self.included(base)
base.class_eval do
include InstanceMethods
- alias_method_chain :assign_shortcuts, :flash
- alias_method_chain :reset_session, :flash
+ alias_method_chain :perform_action, :flash
+ alias_method_chain :reset_session, :flash
end
end
@@ -135,22 +135,26 @@ def use(k=nil, v=true)
module InstanceMethods #:nodoc:
protected
+ def perform_action_with_flash
+ perform_action_without_flash
+ remove_instance_variable(:@_flash) if defined? @_flash
+ end
+
def reset_session_with_flash
reset_session_without_flash
- remove_instance_variable(:@_flash)
+ remove_instance_variable(:@_flash) if defined? @_flash
end
# Access the contents of the flash. Use <tt>flash["notice"]</tt> to
# read a notice you put there or <tt>flash["notice"] = "hello"</tt>
# to put a new one.
def flash #:doc:
- @_flash ||= session["flash"] ||= FlashHash.new
- end
+ unless defined? @_flash
+ @_flash = session["flash"] ||= FlashHash.new
+ @_flash.sweep
+ end
- private
- def assign_shortcuts_with_flash(request, response) #:nodoc:
- assign_shortcuts_without_flash(request, response)
- flash.sweep if @_session
+ @_flash
end
end
end
@@ -232,7 +232,7 @@ def flash
# Do we have a flash?
def has_flash?
- !session['flash'].empty?
+ !flash.empty?
end
# Do we have a flash that has contents?

0 comments on commit 7c09050

Please sign in to comment.