Class: ActionDispatch::Flash::FlashHash
Instance Method Summary (collapse)
-
- (Object) []=(k, v)
:nodoc:.
-
- (Object) alert
Convenience accessor for flash.
-
- (Object) alert=(message)
Convenience accessor for flash=.
-
- (Object) discard(k = nil)
Marks the entire flash or a single flash entry to be discarded by the end of the current action:.
-
- (FlashHash) initialize
constructor
:nodoc:.
-
- (Object) keep(k = nil)
Keeps either the entire current flash or a specific flash entry available for the next action:.
-
- (Object) notice
Convenience accessor for flash.
-
- (Object) notice=(message)
Convenience accessor for flash=.
-
- (Object) now
Sets a flash that will not be available to the next action, only to the current.
-
- (Object) replace(h)
:nodoc:.
-
- (Object) sweep
Mark for removal entries that were kept, and delete unkept ones.
-
- (Object) update(h)
(also: #merge!)
:nodoc:.
Methods inherited from Hash
#as_json, #assert_valid_keys, #deep_merge, #deep_merge!, #diff, #encode_json, #except, #except!, #extract!, #extractable_options?, from_xml, #reverse_merge, #reverse_merge!, #slice, #slice!, #stringify_keys, #stringify_keys!, #symbolize_keys, #symbolize_keys!, #to_param, #to_xml, #with_indifferent_access
Constructor Details
- (FlashHash) initialize
:nodoc:
70 71 72 73 |
# File 'actionpack/lib/action_dispatch/middleware/flash.rb', line 70 def initialize #:nodoc: super @used = Set.new end |
Instance Method Details
- (Object) []=(k, v)
:nodoc:
75 76 77 78 |
# File 'actionpack/lib/action_dispatch/middleware/flash.rb', line 75 def []=(k, v) #:nodoc: keep(k) super end |
- (Object) alert
Convenience accessor for flash
140 141 142 |
# File 'actionpack/lib/action_dispatch/middleware/flash.rb', line 140 def alert self[:alert] end |
- (Object) alert=(message)
Convenience accessor for flash=
145 146 147 |
# File 'actionpack/lib/action_dispatch/middleware/flash.rb', line 145 def alert=() self[:alert] = end |
- (Object) discard(k = nil)
Marks the entire flash or a single flash entry to be discarded by the end of the current action:
flash.discard # discard the entire flash at the end of the current action
flash.discard(:warning) # discard only the "warning" entry at the end of the current action
118 119 120 |
# File 'actionpack/lib/action_dispatch/middleware/flash.rb', line 118 def discard(k = nil) use(k) end |
- (Object) keep(k = nil)
Keeps either the entire current flash or a specific flash entry available for the next action:
flash.keep # keeps the entire flash
flash.keep(:notice) # keeps only the "notice" entry, the rest of the flash is discarded
110 111 112 |
# File 'actionpack/lib/action_dispatch/middleware/flash.rb', line 110 def keep(k = nil) use(k, false) end |
- (Object) notice
Convenience accessor for flash
150 151 152 |
# File 'actionpack/lib/action_dispatch/middleware/flash.rb', line 150 def notice self[:notice] end |
- (Object) notice=(message)
Convenience accessor for flash=
155 156 157 |
# File 'actionpack/lib/action_dispatch/middleware/flash.rb', line 155 def notice=() self[:notice] = end |
- (Object) now
Sets a flash that will not be available to the next action, only to the current.
flash.now[:message] = "Hello current action"
This method enables you to use the flash as a central messaging system in your app. When you need to pass an object to the next action, you use the standard flash assign ([]=). When you need to pass an object to the current action, you use now, and your object will vanish when the current action is done.
Entries set via now are accessed the same way as standard entries: flash['my-key'].
102 103 104 |
# File 'actionpack/lib/action_dispatch/middleware/flash.rb', line 102 def now FlashNow.new(self) end |
- (Object) replace(h)
:nodoc:
87 88 89 90 |
# File 'actionpack/lib/action_dispatch/middleware/flash.rb', line 87 def replace(h) #:nodoc: @used = Set.new super end |
- (Object) sweep
Mark for removal entries that were kept, and delete unkept ones.
This method is called automatically by filters, so you generally don't need to care about it.
125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'actionpack/lib/action_dispatch/middleware/flash.rb', line 125 def sweep #:nodoc: keys.each do |k| unless @used.include?(k) @used << k else delete(k) @used.delete(k) end end # clean up after keys that could have been left over by calling reject! or shift on the flash (@used - keys).each{ |k| @used.delete(k) } end |
- (Object) update(h) Also known as: merge!
:nodoc:
80 81 82 83 |
# File 'actionpack/lib/action_dispatch/middleware/flash.rb', line 80 def update(h) #:nodoc: h.keys.each { |k| keep(k) } super end |