class Hamilton::Context

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:

Defined in:

context.cr

Constructors

Instance Method Summary

Instance methods inherited from class Reference

==(other : Hamilton::Any) ==

Instance methods inherited from class Object

===(other : Hamilton::Any) ===

Constructor Detail

def self.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


Instance Method Detail

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


def clean_data(key : Int64 | String | Symbol) #

Reset the data for the key.


def clean_method(key : Int64 | String | Symbol) #

Reset the method for the key.


def delete(key : Int64 | String | Symbol) #

Delete the key from the storage.


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


def get?(key : Int64 | String | Symbol) #

Return the context for the key.


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


def get_data?(key : Int64 | String | Symbol) #

Return the data for the key.


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


def get_method?(key : Int64 | String | Symbol) #

Return the method for the key.


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

Setter for the pair key, value.


def set(key : Int64 | String | Symbol, method : Symbol) #

Setter that sets only method for the key.


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

Setter that sets only data for the key.