Class: Roda::RodaPlugins::Flash::FlashHash
- Inherits:
-
Hash
- Object
- Hash
- Roda::RodaPlugins::Flash::FlashHash
- Defined in:
- lib/roda/plugins/flash.rb
Overview
Simple flash hash, where assiging to the hash updates the flash used in the following request.
Instance Attribute Summary collapse
-
#next ⇒ Object
readonly
The flash hash for the next request.
Instance Method Summary collapse
-
#[]=(k, v) ⇒ Object
Update the next hash with the given key and value.
-
#discard(key = (no_arg=true)) ⇒ Object
Remove given key from the next hash, or clear the next hash if no argument is given.
-
#initialize(hash = {}) ⇒ FlashHash
constructor
Setup the next hash when initializing, and handle treat nil as a new empty hash.
-
#keep(key = (no_arg=true)) ⇒ Object
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.
-
#sweep ⇒ Object
Replace the current hash with the next hash and clear the next hash.
Constructor Details
#initialize(hash = {}) ⇒ FlashHash
Setup the next hash when initializing, and handle treat nil as a new empty hash.
41 42 43 44 |
# File 'lib/roda/plugins/flash.rb', line 41 def initialize(hash={}) super(hash||{}) @next = {} end |
Instance Attribute Details
#next ⇒ Object (readonly)
The flash hash for the next request. This is what gets written to by #[]=.
34 35 36 |
# File 'lib/roda/plugins/flash.rb', line 34 def next @next end |
Instance Method Details
#[]=(k, v) ⇒ Object
Update the next hash with the given key and value.
47 48 49 |
# File 'lib/roda/plugins/flash.rb', line 47 def []=(k, v) @next[k] = v end |
#discard(key = (no_arg=true)) ⇒ Object
Remove given key from the next hash, or clear the next hash if no argument is given.
53 54 55 56 57 58 59 |
# File 'lib/roda/plugins/flash.rb', line 53 def discard(key=(no_arg=true)) if no_arg @next.clear else @next.delete(key) end end |
#keep(key = (no_arg=true)) ⇒ Object
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.
64 65 66 67 68 69 70 |
# File 'lib/roda/plugins/flash.rb', line 64 def keep(key=(no_arg=true)) if no_arg @next.merge!(self) else self[key] = self[key] end end |
#sweep ⇒ Object
Replace the current hash with the next hash and clear the next hash.
73 74 75 76 77 |
# File 'lib/roda/plugins/flash.rb', line 73 def sweep replace(@next) @next.clear self end |