Class: ApiMapper::Router

Inherits:
Object
  • Object
show all
Defined in:
lib/api_mapper/router.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.add_route(method, mapper, path) ⇒ Object



16
17
18
# File 'lib/api_mapper/router.rb', line 16

def add_route(method, mapper, path)
  routes << Route.new(method, mapper, path)
end

.get(path, mapper) ⇒ Object



4
5
6
# File 'lib/api_mapper/router.rb', line 4

def get(path, mapper)
  add_route(:get, path, mapper)
end

.patch(path, mapper) ⇒ Object



8
9
10
# File 'lib/api_mapper/router.rb', line 8

def patch(path, mapper)
  add_route(:patch, path, mapper)
end

.post(path, mapper) ⇒ Object



12
13
14
# File 'lib/api_mapper/router.rb', line 12

def post(path, mapper)
  add_route(:post, path, mapper)
end

.routesObject



20
21
22
# File 'lib/api_mapper/router.rb', line 20

def routes
  @routes ||= []
end

Instance Method Details

#resolve(method, path) ⇒ Object



25
26
27
# File 'lib/api_mapper/router.rb', line 25

def resolve(method, path)
  self.class.routes.find { |route| route.match(method, path) }
end