class Marten::HTTP::FlashStore

Overview

Represents a flash messages store.

This store provides a way to pass basic string messages from one handler to another. Any string value that is set in this store will be available to the next handler processing the next request, and then it will be cleared out.

Included Modules

Defined in:

marten/http/flash_store.cr
marten/template/ext/marten/http/flash_store.cr

Constructors

Class Method Summary

Instance Method Summary

Macros inherited from module Marten::Template::CanDefineTemplateAttributes

template_attributes(*names) template_attributes

Constructor Detail

def self.new(flashes : Hash(String, String) = {} of String => String, discard : Array(String) = [] of String) #

[View source]

Class Method Detail

def self.from_session(session : Session::Store::Base) #

Allows to initialize a flash store from a session store.

Flash session values that were previously set (likely by the flash middleware) will be used to populate the new flash store.


[View source]

Instance Method Detail

def [](key : String | Symbol) #

Returns the message for the passed key, or raises a KeyError exception if not found.


[View source]
def []=(key : String | Symbol, value : String) #

Allows to set a flash message for a given key.


[View source]
def []?(key : String | Symbol) #

Returns the message for the passed key, or nil if not found.


[View source]
def clear #

Clears the flash store and returns it.


[View source]
def delete(key : String | Symbol) #

Deletes the message for the passed key and returns its value, otherwise returns nil.


[View source]
def delete(key : String | Symbol, &block) #

Deletes the message for the passed key and returns its value, or calls a block with the key when not found.


[View source]
def discard(key : Nil | String | Symbol = nil) #

Discards all the flash messages or either one specific flash message key by the end of the current request.


[View source]
def each(*args, **options) #

Iterates over all the flash messages in the current store.


[View source]
def each(*args, **options, &) #

Iterates over all the flash messages in the current store.


[View source]
def empty?(*args, **options) #

Returns true if the flash store is empty.


[View source]
def empty?(*args, **options, &) #

Returns true if the flash store is empty.


[View source]
def fetch(key : String | Symbol, default) #

Returns the message for the passed key, or the passed default if not found.


[View source]
def fetch(key : String | Symbol, &) #

Returns the message for the passed key, or calls a block with the key when not found.


[View source]
def has_key?(key : String | Symbol) #

Returns true if a message associated with the passed key exists.


[View source]
def keep(key : Nil | String | Symbol = nil) #

Keeps all the flash messages or either one specific flash message key for the next request.


[View source]
def persist(session : Session::Store::Base) : Nil #

Persists the content of the current flash store into the passed session store.


[View source]
def size(*args, **options) #

Returns the size of the flash store.


[View source]
def size(*args, **options, &) #

Returns the size of the flash store.


[View source]