Class: Flame::Dispatcher
- Inherits:
-
Object
show all
- Includes:
- Static
- Defined in:
- lib/flame/dispatcher.rb,
lib/flame/static.rb
Overview
Helpers for dispatch Flame::Application#call
Defined Under Namespace
Modules: Static
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Static
#return_static, #static_cached?, #try_static
Constructor Details
#initialize(app, env) ⇒ Dispatcher
Returns a new instance of Dispatcher.
17
18
19
20
21
22
|
# File 'lib/flame/dispatcher.rb', line 17
def initialize(app, env)
@app = app
@env = env
@request = Flame::Request.new(env)
@response = Flame::Response.new
end
|
Instance Attribute Details
#request ⇒ Object
Returns the value of attribute request.
11
12
13
|
# File 'lib/flame/dispatcher.rb', line 11
def request
@request
end
|
#response ⇒ Object
Returns the value of attribute response.
11
12
13
|
# File 'lib/flame/dispatcher.rb', line 11
def response
@response
end
|
Instance Method Details
#config ⇒ Object
52
53
54
|
# File 'lib/flame/dispatcher.rb', line 52
def config
@app.config
end
|
#cookies ⇒ Object
48
49
50
|
# File 'lib/flame/dispatcher.rb', line 48
def cookies
@cookies ||= Cookies.new(request.cookies, response)
end
|
#halt(new_status = nil, body = nil, new_headers = {}) ⇒ Object
63
64
65
66
67
68
69
70
71
72
73
|
# File 'lib/flame/dispatcher.rb', line 63
def halt(new_status = nil, body = nil, = {})
case new_status
when String then body = new_status
when Integer then status new_status
end
body = default_body if body.nil? && response.body.empty?
response.body = body if body
response..merge!()
throw :halt
end
|
#params ⇒ Object
40
41
42
|
# File 'lib/flame/dispatcher.rb', line 40
def params
@params ||= request.params.merge(request.params.keys_to_sym)
end
|
#path_to(ctrl, action = :index, args = {}) ⇒ Object
56
57
58
59
60
61
|
# File 'lib/flame/dispatcher.rb', line 56
def path_to(ctrl, action = :index, args = {})
route = @app.class.router.find_route(controller: ctrl, action: action)
fail RouteNotFoundError.new(ctrl, action) unless route
path = route.assign_arguments(args)
path.empty? ? '/' : path
end
|
#run! ⇒ Object
24
25
26
27
28
29
30
31
32
|
# File 'lib/flame/dispatcher.rb', line 24
def run!
catch :halt do
try_route ||
try_static ||
try_static(File.join(__dir__, '..', '..', 'public')) ||
try_error(404)
end
response.finish
end
|
#session ⇒ Object
44
45
46
|
# File 'lib/flame/dispatcher.rb', line 44
def session
request.session
end
|
#status(value = nil) ⇒ Object
34
35
36
37
38
|
# File 'lib/flame/dispatcher.rb', line 34
def status(value = nil)
response.status ||= 200
response.['X-Cascade'] = 'pass' if value == 404
value ? response.status = value : response.status
end
|