Permalink
Browse files

extract alert= and notice= examples to FlashHash#now [ci skip]

  • Loading branch information...
Francesco Rodriguez
Francesco Rodriguez committed Jan 4, 2013
1 parent dc14b89 commit 654f0d6a1520fc6a0a0396e78255a9ec50594e44
Showing with 15 additions and 17 deletions.
  1. +15 −17 actionpack/lib/action_dispatch/middleware/flash.rb
@@ -59,22 +59,12 @@ def [](k)
@flash[k]
end
- # Convenience accessor for flash.now[:alert]=
- #
- # Example:
- #
- # flash.alert = "Error: no cheezburger"
- # # Equivlant to flash[:alert] = "No cheezburger"
+ # Convenience accessor for <tt>flash.now[:alert]=</tt>.
def alert=(message)
self[:alert] = message
end
- # Convenience accessor for flash.now[:notice]=
- #
- # Example:
- #
- # flash.notice = "Bukkit stolen"
- # # Equivlant to flash[:notice] = "Bukkit stolen"
+ # Convenience accessor for <tt>flash.now[:notice]=</tt>.
def notice=(message)
self[:notice] = message
end
@@ -92,7 +82,7 @@ def self.from_session_value(value)
else
new
end
-
+
flash.tap(&:sweep)
end
@@ -179,6 +169,14 @@ def replace(h) #:nodoc:
# vanish when the current action is done.
#
# Entries set via <tt>now</tt> are accessed the same way as standard entries: <tt>flash['my-key']</tt>.
+ #
+ # Also, brings two convenience accessors:
+ #
+ # flash.now.alert = "Beware now!"
+ # # Equivalent to flash.now[:alert] = "Beware now!"
+ #
+ # flash.now.notice = "Good luck now!"
+ # # Equivalent to flash.now[:notice] = "Good luck now!"
def now
@now ||= FlashNow.new(self)
end
@@ -209,22 +207,22 @@ def sweep #:nodoc:
@discard.replace @flashes.keys
end
- # Convenience accessor for flash[:alert]
+ # Convenience accessor for <tt>flash[:alert]</tt>.
def alert
self[:alert]
end
- # Convenience accessor for flash[:alert]=
+ # Convenience accessor for <tt>flash[:alert]=</tt>.
def alert=(message)
self[:alert] = message
end
- # Convenience accessor for flash[:notice]
+ # Convenience accessor for <tt>flash[:notice]</tt>.
def notice
self[:notice]
end
- # Convenience accessor for flash[:notice]=
+ # Convenience accessor for <tt>flash[:notice]=</tt>.
def notice=(message)
self[:notice] = message
end

0 comments on commit 654f0d6

Please sign in to comment.