Class: Wouter::Endpoint
- Inherits:
-
Object
show all
- Defined in:
- lib/wouter/endpoint.rb
Overview
‘Wouter::Endpoint` is a class to help define Rack compatible endpoints that can be assigned to a route path. Each `Wouter::Endpoint` instance is a Rack application of it’s own. It provides convience methods for creating endpoints.
Defined Under Namespace
Classes: NotImplementedError
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(req, res) ⇒ Endpoint
Returns a new instance of Endpoint.
12
13
14
15
|
# File 'lib/wouter/endpoint.rb', line 12
def initialize(req, res)
@req = req
@res = res
end
|
Instance Attribute Details
#req ⇒ Object
Returns the value of attribute req.
10
11
12
|
# File 'lib/wouter/endpoint.rb', line 10
def req
@req
end
|
#res ⇒ Object
Returns the value of attribute res.
10
11
12
|
# File 'lib/wouter/endpoint.rb', line 10
def res
@res
end
|
Class Method Details
.call(env) ⇒ Object
17
18
19
20
21
22
23
24
25
|
# File 'lib/wouter/endpoint.rb', line 17
def self.call(env)
endpoint = new(Rack::Request.new(env), Rack::Response.new)
response = endpoint.respond
return response.finish if response.is_a?(Rack::Response)
endpoint.res.write response
endpoint.res.finish
end
|
Instance Method Details
35
36
37
38
|
# File 'lib/wouter/endpoint.rb', line 35
def (hash = nil)
@res..merge! hash if hash
@res.
end
|
#params ⇒ Object
31
32
33
|
# File 'lib/wouter/endpoint.rb', line 31
def params
@req.params
end
|
#respond ⇒ Object
27
28
29
|
# File 'lib/wouter/endpoint.rb', line 27
def respond
raise NotImplementedError, 'you must implemented #respond in your Wouter::Endpoint class'
end
|
#status(code) ⇒ Object
40
41
42
43
|
# File 'lib/wouter/endpoint.rb', line 40
def status(code)
@res.status = code
@res.status
end
|