1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# Roda ships no signatures. This is the routing surface web.rb uses and
# no more of it.
#
# Matchers stay untyped on purpose. Roda's matcher vocabulary is open,
# and the block arguments a match yields depend on which matcher matched.
class Roda
  # The configure blocks vary by plugin (error_handler passes the
  # exception), so the block takes anything, like the matchers below.
  def self.plugin: (Symbol plugin, *untyped args, **untyped options) ?{ (*untyped) [self: instance] -> untyped } -> void

  # The block is the router, run against a fresh instance per request.
  def self.route: () { (RodaRequest) [self: instance] -> untyped } -> void

  def self.freeze: () -> singleton(Roda)

  def self.app: () -> untyped

  # The route_csrf plugin's: halts a request whose token does not check
  # out, and hands out the token a form has to post back.
  def check_csrf!: () -> void
  def csrf_token: (?String? path, ?String? method) -> String

  def response: () -> RodaResponse

  # The sessions plugin's: the signed cookie session.
  def session: () -> Hash[String, untyped]

  class RodaRequest
    def env: () -> Hash[String, untyped]

    # Scheme, host and port, as the client reached the app.
    def base_url: () -> String

    def is: (*untyped matchers) { (*untyped) -> untyped } -> void
    def on: (*untyped matchers) { (*untyped) -> untyped } -> void
    def root: () { () -> untyped } -> void
    def get: (*untyped matchers) ?{ (*untyped) -> untyped } -> void
    def post: (*untyped matchers) ?{ (*untyped) -> untyped } -> void

    # Values stay untyped: repeated keys arrive as arrays.
    def params: () -> Hash[String, untyped]

    def redirect: (String path, ?Integer status) -> bot

    # The halt plugin's: ends the request with this status.
    def halt: (?Integer status) -> bot
  end

  class RodaResponse
    def []=: (String header, String value) -> void
    def status=: (Integer status) -> void
  end
end