Skip to content

Commit

Permalink
extract alert= and notice= examples to FlashHash#now [ci skip]
Browse files Browse the repository at this point in the history
  • Loading branch information
Francesco Rodriguez committed Jan 4, 2013
1 parent dc14b89 commit 654f0d6
Showing 1 changed file with 15 additions and 17 deletions.
32 changes: 15 additions & 17 deletions actionpack/lib/action_dispatch/middleware/flash.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -59,22 +59,12 @@ def [](k)
@flash[k] @flash[k]
end end


# Convenience accessor for flash.now[:alert]= # Convenience accessor for <tt>flash.now[:alert]=</tt>.
#
# Example:
#
# flash.alert = "Error: no cheezburger"
# # Equivlant to flash[:alert] = "No cheezburger"
def alert=(message) def alert=(message)
self[:alert] = message self[:alert] = message
end end


# Convenience accessor for flash.now[:notice]= # Convenience accessor for <tt>flash.now[:notice]=</tt>.
#
# Example:
#
# flash.notice = "Bukkit stolen"
# # Equivlant to flash[:notice] = "Bukkit stolen"
def notice=(message) def notice=(message)
self[:notice] = message self[:notice] = message
end end
Expand All @@ -92,7 +82,7 @@ def self.from_session_value(value)
else else
new new
end end

flash.tap(&:sweep) flash.tap(&:sweep)
end end


Expand Down Expand Up @@ -179,6 +169,14 @@ def replace(h) #:nodoc:
# vanish when the current action is done. # 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>. # 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 def now
@now ||= FlashNow.new(self) @now ||= FlashNow.new(self)
end end
Expand Down Expand Up @@ -209,22 +207,22 @@ def sweep #:nodoc:
@discard.replace @flashes.keys @discard.replace @flashes.keys
end end


# Convenience accessor for flash[:alert] # Convenience accessor for <tt>flash[:alert]</tt>.
def alert def alert
self[:alert] self[:alert]
end end


# Convenience accessor for flash[:alert]= # Convenience accessor for <tt>flash[:alert]=</tt>.
def alert=(message) def alert=(message)
self[:alert] = message self[:alert] = message
end end


# Convenience accessor for flash[:notice] # Convenience accessor for <tt>flash[:notice]</tt>.
def notice def notice
self[:notice] self[:notice]
end end


# Convenience accessor for flash[:notice]= # Convenience accessor for <tt>flash[:notice]=</tt>.
def notice=(message) def notice=(message)
self[:notice] = message self[:notice] = message
end end
Expand Down

0 comments on commit 654f0d6

Please sign in to comment.