Class: Rack::HttpRouter
- Inherits:
-
Object
show all
- Includes:
- Action
- Defined in:
- lib/rack-http_router.rb,
lib/rack-http_router/action.rb,
lib/rack-http_router/router.rb,
lib/rack-http_router/router/route.rb,
lib/rack-http_router/router/build_request.rb
Defined Under Namespace
Modules: Action
Classes: Router
Instance Method Summary
collapse
Methods included from Action
erb, #erb, #html, html, #html_response, html_response, included, json, #json, #json_response, json_response, #layout, layout, #redirect_response, redirect_response, #redirect_to, redirect_to, #response, response, #text, text, #text_response, text_response, view, view_response
Constructor Details
#initialize(config = {}) ⇒ HttpRouter
Returns a new instance of HttpRouter.
10
11
12
|
# File 'lib/rack-http_router.rb', line 10
def initialize(config = {})
@router = Router.new(config)
end
|
Instance Method Details
#call(&block) ⇒ Object
14
15
16
17
18
|
# File 'lib/rack-http_router.rb', line 14
def call(&block)
instance_eval(&block)
@router
end
|
#config ⇒ Object
24
25
26
|
# File 'lib/rack-http_router.rb', line 24
def config
@router.config
end
|
#db ⇒ Object
28
29
30
|
# File 'lib/rack-http_router.rb', line 28
def db
@router.config[:db]
end
|
#error(endpoint = -> {}, &block) ⇒ Object
47
48
49
50
51
52
53
|
# File 'lib/rack-http_router.rb', line 47
def error(endpoint = -> {}, &block)
if block_given?
@router.add_error(block)
else
@router.add_error(endpoint)
end
end
|
#not_found(endpoint = -> {}, &block) ⇒ Object
39
40
41
42
43
44
45
|
# File 'lib/rack-http_router.rb', line 39
def not_found(endpoint = -> {}, &block)
if block_given?
@router.add_not_found(block)
else
@router.add_not_found(endpoint)
end
end
|
#route ⇒ Object
20
21
22
|
# File 'lib/rack-http_router.rb', line 20
def route
@router.route
end
|
#scope(name, before: [], &block) ⇒ Object
32
33
34
35
36
37
|
# File 'lib/rack-http_router.rb', line 32
def scope(name, before: [], &block)
@router.append_scope(name, before)
instance_eval(&block)
@router.clear_last_scope
end
|