Class: Gack::Route

Inherits:
Object
  • Object
show all
Defined in:
lib/gack/route.rb

Overview

Route is a Gemini request handler wrapper for a given path

Constant Summary collapse

HandlerMissingError =
Class.new(StandardError)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, &handler) ⇒ Route

Returns a new instance of Route.



10
11
12
13
14
15
16
# File 'lib/gack/route.rb', line 10

def initialize(path, &handler)
  @path = path

  raise HandlerMissingError unless handler

  @handler = handler
end

Instance Attribute Details

#handlerObject (readonly)

Returns the value of attribute handler.



8
9
10
# File 'lib/gack/route.rb', line 8

def handler
  @handler
end

#pathObject (readonly)

Returns the value of attribute path.



8
9
10
# File 'lib/gack/route.rb', line 8

def path
  @path
end

Instance Method Details

#handle_request(request) ⇒ Object



26
27
28
# File 'lib/gack/route.rb', line 26

def handle_request(request)
  handler.call(request)
end

#path_match?(string) ⇒ Boolean



18
19
20
21
22
23
24
# File 'lib/gack/route.rb', line 18

def path_match?(string)
  if path.is_a?(Regexp)
    path.match?(string)
  else
    path.eql?(string)
  end
end