Skip to content

class Athena::HTTP::Session::FlashBag
inherits Reference #

Stores flash messages, messages that are only meant to be shown to the user once, grouped by type. E.g. "notice" or "error".

Reading messages via #get or #all removes them, while #peek and #peek_all leave them in place.

Included modules

Athena::HTTP::Session::BagInterface

Constructors#

.new(storage_key : String = "_athena_flashes")#

View source

Methods#

#add(type : String, message : String) : Nil#

Adds the provided message to those of the provided type.

View source

#all : Hash(String, Array(String))#

Returns and removes the messages of all types.

View source

#clear : Nil#

Removes all of this bag's data.

View source

#empty? : Bool#

Returns true if this bag has no data to persist, otherwise false.

View source

#get(type : String, default : Array(String) = [] of String) : Array(String)#

Returns and removes the messages of the provided type, or returns the provided default if there are none.

View source

#has?(type : String) : Bool#

Returns true if there are messages of the provided type, otherwise false.

View source

#keys : Array(String)#

Returns the types that have messages.

View source

#load(pull : JSON::PullParser | Nil) : Nil#

Loads this bag's data from the provided pull parser, positioned at the value persisted under #storage_key. Resets this bag to empty if pull is nil, i.e. nothing was persisted under it.

View source

#name : String#

Returns the name of this bag, used to retrieve it via AHTTP::Session#bag.

View source

#name=(name : String)#

:inherit:

View source

#peek(type : String, default : Array(String) = [] of String) : Array(String)#

Returns the messages of the provided type, or the provided default if there are none, without removing them.

View source

#peek_all : Hash(String, Array(String))#

Returns the messages of all types, without removing them.

View source

#set(type : String, messages : String | Array(String)) : Nil#

Replaces the messages of the provided type with the provided messages.

View source

#set_all(messages : Hash(String, Array(String))) : Nil#

Replaces the messages of all types with the provided messages.

View source

#storage_key : String#

Returns the key this bag's data is persisted under within the session.

View source

#to_json(builder : JSON::Builder) : Nil#

Writes this bag's data to the provided builder, to be persisted under #storage_key.

View source