Class: Fluent::PluginHelper::HttpServer::Router

Inherits:
Object
  • Object
show all
Defined in:
lib/fluent/plugin_helper/http_server/router.rb

Defined Under Namespace

Classes: NotFoundApp

Instance Method Summary collapse

Constructor Details

#initialize(default_app = nil) ⇒ Router

Returns a new instance of Router.



29
30
31
32
# File 'lib/fluent/plugin_helper/http_server/router.rb', line 29

def initialize(default_app = nil)
  @router = { get: {}, head: {}, post: {}, put: {}, patch: {}, delete: {}, connect: {}, options: {}, trace: {} }
  @default_app = default_app || NotFoundApp
end

Instance Method Details

#mount(method, path, app) ⇒ Object

Parameters:

  • method (Symbol)
  • path (String)
  • app (Object)


37
38
39
40
41
42
43
# File 'lib/fluent/plugin_helper/http_server/router.rb', line 37

def mount(method, path, app)
  if @router[method].include?(path)
    raise "#{path} is already mounted"
  end

  @router[method][path] = app
end

#route!(method, path, request) ⇒ Object

Parameters:



48
49
50
# File 'lib/fluent/plugin_helper/http_server/router.rb', line 48

def route!(method, path, request)
  @router.fetch(method).fetch(path, @default_app).call(request)
end