class Makanai::Router

Attributes

routes[RW]

Public Class Methods

new() click to toggle source
# File lib/makanai/router.rb, line 11
def initialize
  @routes = []
end

Public Instance Methods

bind!(url:, method:) click to toggle source
# 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) click to toggle source
# File lib/makanai/router.rb, line 27
def delete(path, &block)
  @routes << Route.new(path: path, process: block, method: 'DELETE')
end
get(path, &block) click to toggle source
# File lib/makanai/router.rb, line 15
def get(path, &block)
  @routes << Route.new(path: path, process: block, method: 'GET')
end
post(path, &block) click to toggle source
# File lib/makanai/router.rb, line 19
def post(path, &block)
  @routes << Route.new(path: path, process: block, method: 'POST')
end
put(path, &block) click to toggle source
# File lib/makanai/router.rb, line 23
def put(path, &block)
  @routes << Route.new(path: path, process: block, method: 'PUT')
end