Class: Gack::Route
- Inherits:
-
Object
- Object
- Gack::Route
- 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
-
#handler ⇒ Object
readonly
Returns the value of attribute handler.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #handle_request(request) ⇒ Object
-
#initialize(path, &handler) ⇒ Route
constructor
A new instance of Route.
- #path_match?(string) ⇒ Boolean
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
#handler ⇒ Object (readonly)
Returns the value of attribute handler.
8 9 10 |
# File 'lib/gack/route.rb', line 8 def handler @handler end |
#path ⇒ Object (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 |