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 53 def initialize(hash={}) 54 super(hash||{}) 55 @next = {} 56 end
Public Instance methods
[]=(k, v)
Update the next hash with the given key and value.
[show source]
# File lib/roda/plugins/flash.rb 59 def []=(k, v) 60 @next[k] = v 61 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 65 def discard(key=(no_arg=true)) 66 if no_arg 67 @next.clear 68 else 69 @next.delete(key) 70 end 71 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 76 def keep(key=(no_arg=true)) 77 if no_arg 78 @next.merge!(self) 79 else 80 self[key] = self[key] 81 end 82 end
sweep()
Replace the current hash with the next hash and clear the next hash.
[show source]
# File lib/roda/plugins/flash.rb 85 def sweep 86 replace(@next) 87 @next.clear 88 self 89 end