Module: Truss::Router
- Extended by:
- Router
- Included in:
- Router
- Defined in:
- lib/truss/router.rb,
lib/truss/router/node.rb,
lib/truss/router/routes.rb,
lib/truss/router/request.rb,
lib/truss/router/version.rb,
lib/truss/router/routeset.rb,
lib/truss/router/routes/get.rb,
lib/truss/router/routes/put.rb,
lib/truss/router/routes/head.rb,
lib/truss/router/routes/post.rb,
lib/truss/router/routes/patch.rb,
lib/truss/router/routes/delete.rb,
lib/truss/router/routes/options.rb
Defined Under Namespace
Modules: Routes
Classes: Node, Request, Routeset
Constant Summary
collapse
- VERSION =
"0.0.2"
Instance Method Summary
collapse
-
#call(env) ⇒ Object
-
#delete(path, endpoint, opts = {}) ⇒ Object
-
#draw(&block) ⇒ Object
-
#get(path, endpoint, opts = {}) ⇒ Object
-
#head(path, endpoint, opts = {}) ⇒ Object
-
#options(path, endpoint, opts = {}) ⇒ Object
-
#patch(path, endpoint, opts = {}) ⇒ Object
-
#post(path, endpoint, opts = {}) ⇒ Object
-
#put(path, endpoint, opts = {}) ⇒ Object
-
#reset! ⇒ Object
-
#routeset ⇒ Object
Instance Method Details
#call(env) ⇒ Object
51
52
53
54
55
56
57
58
59
|
# File 'lib/truss/router.rb', line 51
def call env
request = Request.new(env.dup)
route = routeset.find_route(request)
if route
route.call(request)
else
[404, {'Content-Type' => 'text/plain'}, ["Not Found"]]
end
end
|
#delete(path, endpoint, opts = {}) ⇒ Object
43
44
45
|
# File 'lib/truss/router.rb', line 43
def delete(path, endpoint, opts={})
build_node :Delete, path, endpoint, opts
end
|
#draw(&block) ⇒ Object
10
11
12
13
|
# File 'lib/truss/router.rb', line 10
def draw(&block)
raise ArgumentError unless block_given?
block.call(self)
end
|
#get(path, endpoint, opts = {}) ⇒ Object
19
20
21
|
# File 'lib/truss/router.rb', line 19
def get(path, endpoint, opts={})
build_node :Get, path, endpoint, opts
end
|
#head(path, endpoint, opts = {}) ⇒ Object
31
32
33
|
# File 'lib/truss/router.rb', line 31
def head(path, endpoint, opts={})
build_node :Head, path, endpoint, opts
end
|
#options(path, endpoint, opts = {}) ⇒ Object
27
28
29
|
# File 'lib/truss/router.rb', line 27
def options(path, endpoint, opts={})
build_node :Options, path, endpoint, opts
end
|
#patch(path, endpoint, opts = {}) ⇒ Object
39
40
41
|
# File 'lib/truss/router.rb', line 39
def patch(path, endpoint, opts={})
build_node :Patch, path, endpoint, opts
end
|
#post(path, endpoint, opts = {}) ⇒ Object
23
24
25
|
# File 'lib/truss/router.rb', line 23
def post(path, endpoint, opts={})
build_node :Post, path, endpoint, opts
end
|
#put(path, endpoint, opts = {}) ⇒ Object
35
36
37
|
# File 'lib/truss/router.rb', line 35
def put(path, endpoint, opts={})
build_node :Put, path, endpoint, opts
end
|
#reset! ⇒ Object
47
48
49
|
# File 'lib/truss/router.rb', line 47
def reset!
@routeset = Truss::Router::Routeset.new
end
|
#routeset ⇒ Object
15
16
17
|
# File 'lib/truss/router.rb', line 15
def routeset
@routeset ||= Truss::Router::Routeset.new
end
|