Class: Makanai::Router
- Inherits:
-
Object
- Object
- Makanai::Router
- Defined in:
- lib/makanai/router.rb
Defined Under Namespace
Instance Attribute Summary collapse
-
#routes ⇒ Object
Returns the value of attribute routes.
Instance Method Summary collapse
- #bind!(url:, method:) ⇒ Object
- #delete(path, &block) ⇒ Object
- #get(path, &block) ⇒ Object
-
#initialize ⇒ Router
constructor
A new instance of Router.
- #post(path, &block) ⇒ Object
- #put(path, &block) ⇒ Object
Constructor Details
#initialize ⇒ Router
Returns a new instance of Router.
11 12 13 |
# File 'lib/makanai/router.rb', line 11 def initialize @routes = [] end |
Instance Attribute Details
#routes ⇒ Object
Returns the value of attribute routes.
9 10 11 |
# File 'lib/makanai/router.rb', line 9 def routes @routes end |
Instance Method Details
#bind!(url:, method:) ⇒ Object
31 32 33 34 35 36 |
# File 'lib/makanai/router.rb', line 31 def bind!(url:, method:) path = URI.parse(url).path routes.find { |route| route.match?(path: path, method: method) }.tap do |route| raise NotFound if route.nil? end end |
#delete(path, &block) ⇒ Object
27 28 29 |
# File 'lib/makanai/router.rb', line 27 def delete(path, &block) @routes << Route.new(path: path, process: block, method: 'DELETE') end |
#get(path, &block) ⇒ Object
15 16 17 |
# File 'lib/makanai/router.rb', line 15 def get(path, &block) @routes << Route.new(path: path, process: block, method: 'GET') end |