Class: Lotus::Action::Flash Private
- Inherits:
-
Object
- Object
- Lotus::Action::Flash
- Defined in:
- lib/lotus/action/flash.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Container useful to transport data with the HTTP session It has a life span of one HTTP request or redirect.
Constant Summary collapse
- SESSION_KEY =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Session key where the data is stored
:__flash
Instance Method Summary collapse
-
#[](key) ⇒ Object, NilClass
private
Get the value associated to the given key, if any.
-
#[]=(key, value) ⇒ Object
private
Set the given value for the given key.
-
#clear ⇒ void
private
Removes entirely the flash from the session if it has stale contents or if empty.
-
#empty? ⇒ TrueClass, FalseClass
private
Check if there are contents stored in the flash from the current or the previous request.
-
#initialize(session, request_id) ⇒ Lotus::Action::Flash
constructor
private
Initialize a new Flash instance.
Constructor Details
#initialize(session, request_id) ⇒ Lotus::Action::Flash
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Initialize a new Flash instance
24 25 26 27 28 29 30 |
# File 'lib/lotus/action/flash.rb', line 24 def initialize(session, request_id) @session = session @request_id = request_id session[SESSION_KEY] ||= {} session[SESSION_KEY][request_id] ||= {} end |
Instance Method Details
#[](key) ⇒ Object, NilClass
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Get the value associated to the given key, if any
49 50 51 52 53 |
# File 'lib/lotus/action/flash.rb', line 49 def [](key) data.fetch(key) do _values.find {|data| !data[key].nil? } end end |
#[]=(key, value) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Set the given value for the given key
39 40 41 |
# File 'lib/lotus/action/flash.rb', line 39 def []=(key, value) data[key] = value end |
#clear ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Removes entirely the flash from the session if it has stale contents or if empty.
62 63 64 65 66 67 68 69 70 71 |
# File 'lib/lotus/action/flash.rb', line 62 def clear # FIXME we're just before a release and I can't find a proper way to reproduce # this bug that I've found via a browser. # # It may happen that `#flash` is nil, and those two methods will fail unless flash.nil? expire_stale! remove! end end |
#empty? ⇒ TrueClass, FalseClass
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Check if there are contents stored in the flash from the current or the previous request.
80 81 82 |
# File 'lib/lotus/action/flash.rb', line 80 def empty? _values.all?(&:empty?) end |