mirror of
https://gitea.invidious.io/iv-org/shard-kemal.git
synced 2024-08-15 00:53:36 +00:00
User defined context store types (#339)
allow the context storage to handle any types
This commit is contained in:
parent
48128696c6
commit
0b4856b741
4 changed files with 43 additions and 2 deletions
|
@ -4,8 +4,13 @@
|
|||
# Instances of this class are passed to an `HTTP::Server` handler.
|
||||
class HTTP::Server
|
||||
class Context
|
||||
alias StoreTypes = Nil | String | Int32 | Int64 | Float64 | Bool
|
||||
getter store = {} of String => StoreTypes
|
||||
# :nodoc:
|
||||
STORE_MAPPINGS = [ Nil, String, Int32, Int64, Float64, Bool ]
|
||||
|
||||
macro finished
|
||||
alias StoreTypes = Union({{ *STORE_MAPPINGS }})
|
||||
getter store = {} of String => StoreTypes
|
||||
end
|
||||
|
||||
def params
|
||||
@request.url_params ||= route_lookup.params
|
||||
|
|
|
@ -76,3 +76,15 @@ macro halt(env, status_code = 200, response = "")
|
|||
{{env}}.response.close
|
||||
next
|
||||
end
|
||||
|
||||
# Extends context storage with user defined types.
|
||||
#
|
||||
# class User
|
||||
# property name
|
||||
# end
|
||||
#
|
||||
# add_context_storage_type(User)
|
||||
#
|
||||
macro add_context_storage_type(type)
|
||||
{{ HTTP::Server::Context::STORE_MAPPINGS.push(type) }}
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue