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#
Methods#
#all : Hash(String, String)#
Returns all attributes, with their values serialized as JSON.
#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.
#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.
#has?(name : String) : Bool#
Returns true if an attribute with the provided name exists, otherwise false.
#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.
#name : String#
Returns the name of this bag, used to retrieve it via AHTTP::Session#bag.
#remove(name : String) : Nil#
Removes the attribute with the provided name, if it exists.
#set(name : String, value : _) : Nil#
Sets the attribute with the provided name to the provided value.
#storage_key : String#
Returns the key this bag's data is persisted under within the session.
#to_json(builder : JSON::Builder) : Nil#
Writes this bag's data to the provided builder, to be persisted under #storage_key.