class

Hamilton::Context

Inherits Reference < Object

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 method
  • data: Hamilton::Storage) -- storage for some specific data

Constructors

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.

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

Source

Instance methods

clean(key : Int64 | String | Symbol)

Reset the context for the key, i.e. the key will map to {method: default_method, data: nil} if present.

Source
clean_data(key : Int64 | String | Symbol)

Reset the data for the key.

Source
clean_method(key : Int64 | String | Symbol)

Reset the method for the key.

Source
delete(key : Int64 | String | Symbol)

Delete the key from the storage.

Source
get(key : Int64 | String | Symbol)

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}.

Source
get?(key : Int64 | String | Symbol)

Return the context for the key.

Source
get_data(key : Int64 | String | Symbol)

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}.

Source
get_data?(key : Int64 | String | Symbol)

Return the data for the key.

Source
get_method(key : Int64 | String | Symbol)

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}.

Source
get_method?(key : Int64 | String | Symbol)

Return the method for the key.

Source
set(key : Int64 | String | Symbol, value : NamedTuple(method: Symbol | Nil, data: Hamilton::Storage))

Setter for the pair key, value.

Source
set(key : Int64 | String | Symbol, method : Symbol)

Setter that sets only method for the key.

Source
set(key : Int64 | String | Symbol, data : Hamilton::Storage)

Setter that sets only data for the key.

Source