Simple flash hash, where assiging to the hash updates the flash used in the following request.
Public Class methods
new(hash={})
Setup the next hash when initializing, and handle treat nil as a new empty hash.
[show source]
# File lib/roda/plugins/flash.rb 51 def initialize(hash={}) 52 super(hash||{}) 53 @next = {} 54 end
Public Instance methods
[]=(k, v)
Update the next hash with the given key and value.
[show source]
# File lib/roda/plugins/flash.rb 57 def []=(k, v) 58 @next[k] = v 59 end
discard(key=(no_arg=true))
Remove given key from the next hash, or clear the next hash if no argument is given.
[show source]
# File lib/roda/plugins/flash.rb 63 def discard(key=(no_arg=true)) 64 if no_arg 65 @next.clear 66 else 67 @next.delete(key) 68 end 69 end
keep(key=(no_arg=true))
Copy the entry with the given key from the current hash to the next hash, or copy all entries from the current hash to the next hash if no argument is given.
[show source]
# File lib/roda/plugins/flash.rb 74 def keep(key=(no_arg=true)) 75 if no_arg 76 @next.merge!(self) 77 else 78 self[key] = self[key] 79 end 80 end
sweep()
Replace the current hash with the next hash and clear the next hash.
[show source]
# File lib/roda/plugins/flash.rb 83 def sweep 84 replace(@next) 85 @next.clear 86 self 87 end