class
Hamilton::Context
- Hamilton::Context
- Reference
- Object
Overview
Context is a storage for some state.
As it was developed primary for Hamilton::CmdHandler, Hamilton::Context maps a key of type
Int64 | String | Symbol to a named tuple with two fields:
method : Symbol | Nil-- name of some methoddata: Hamilton::Storage)-- storage for some specific data
Defined in:
context.crConstructors
-
.new(*, inner : Hash(Int64 | String | Symbol, NamedTuple(method: Symbol | Nil, data: Hamilton::Storage)) = Hash(Int64 | String | Symbol, NamedTuple(method: Symbol | Nil, data: Hamilton::Storage)).new, default_method : Symbol | Nil = nil)
Initializer of the context storage.
Instance Method Summary
-
#clean(key : Int64 | String | Symbol)
Reset the context for the
key, i.e. -
#clean_data(key : Int64 | String | Symbol)
Reset the data for the
key. -
#clean_method(key : Int64 | String | Symbol)
Reset the method for the
key. -
#delete(key : Int64 | String | Symbol)
Delete the
keyfrom the storage. -
#get(key : Int64 | String | Symbol)
Return the context for the
key. -
#get?(key : Int64 | String | Symbol)
Return the context for the
key. -
#get_data(key : Int64 | String | Symbol)
Return the data for the
key. -
#get_data?(key : Int64 | String | Symbol)
Return the data for the
key. -
#get_method(key : Int64 | String | Symbol)
Return the method for the
key. -
#get_method?(key : Int64 | String | Symbol)
Return the method for the
key. -
#set(key : Int64 | String | Symbol, value : NamedTuple(method: Symbol | Nil, data: Hamilton::Storage))
Setter for the pair
key, value. -
#set(key : Int64 | String | Symbol, method : Symbol)
Setter that sets only method for the key.
-
#set(key : Int64 | String | Symbol, data : Hamilton::Storage)
Setter that sets only data for the key.
Instance methods inherited from class Reference
==(other : Hamilton::Any)
==
Instance methods inherited from class Object
===(other : Hamilton::Any)
===
Constructor Detail
Initializer of the context storage.
Optional parameters:
default_method : Symbol | Nil -- something that will be the default value for the method field
inner : Hash(Int32 | String | Symbol, NamedTuple(method: Symbol | Nil, data: Hamilton::Storage)) -- storage itself
Instance Method Detail
Reset the context for the key, i.e. the key will map to {method: default_method, data: nil} if present.
Return the context for the key.
NOTE if there was not a context for the key, it will be iplicitly created with {method: default_method, data: nil}.
Return the data for the key.
NOTE if there was not a context for the key, it will be iplicitly created with {method: default_method, data: nil}.
Return the method for the key.
NOTE if there was not a context for the key, it will be iplicitly created with {method: default_method, data: nil}.
Setter for the pair key, value.
Setter that sets only data for the key.