Class: Reins::Flash
- Inherits:
-
Object
- Object
- Reins::Flash
- Defined in:
- lib/reins/flash.rb
Overview
Defined Under Namespace
Classes: NowProxy
Constant Summary collapse
- SESSION_KEY =
"_flash".freeze
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
-
#initialize(session) ⇒ Flash
constructor
A new instance of Flash.
- #now ⇒ Object
- #sweep! ⇒ Object
Constructor Details
#initialize(session) ⇒ Flash
Returns a new instance of Flash.
9 10 11 12 13 14 |
# File 'lib/reins/flash.rb', line 9 def initialize(session) @session = session @inbound = (session[SESSION_KEY] || {}).dup @outbound = {} @now_store = {} end |
Instance Method Details
#[](key) ⇒ Object
16 17 18 19 20 21 |
# File 'lib/reins/flash.rb', line 16 def [](key) key = key.to_s return @now_store[key] if @now_store.key?(key) @inbound[key] end |
#[]=(key, value) ⇒ Object
23 24 25 |
# File 'lib/reins/flash.rb', line 23 def []=(key, value) @outbound[key.to_s] = value end |
#now ⇒ Object
27 28 29 |
# File 'lib/reins/flash.rb', line 27 def now @now ||= NowProxy.new(@now_store) end |
#sweep! ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/reins/flash.rb', line 31 def sweep! if @outbound.empty? @session.delete(SESSION_KEY) else @session[SESSION_KEY] = @outbound end end |