Skip to content

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

Stores the attributes of an AHTTP::Session.

Each value is stored as JSON, so any type that can be serialized via #to_json and deserialized via .from_json can be stored. E.g. scalars, arrays, hashes, or types that include JSON::Serializable.

Included modules

Athena::HTTP::Session::BagInterface

Constructors#

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

View source

Methods#

#all : Hash(String, String)#

Returns all attributes, with their values serialized as JSON.

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(name : String, type : T.class) : T forall T#

Returns the value of the attribute with the provided name, deserialized as the provided type.

Raises a KeyError if no attribute with that name exists.

View source

#get?(name : String, type : T.class) : T | Nil forall T#

Returns the value of the attribute with the provided name, deserialized as the provided type, or nil if it does not exist.

View source

#has?(name : String) : Bool#

Returns true if an attribute with the provided name exists, otherwise false.

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

#remove(name : String) : Nil#

Removes the attribute with the provided name, if it exists.

View source

#set(name : String, value : _) : Nil#

Sets the attribute with the provided name to the provided value.

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