Module: Ant::Server::Response
Overview
This module provides a function to wrap lambdas arround grape/sinatra You can mount this module as helper in your application and wrap the block with the method ‘process_request`
Class Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
register, resource, resources
Class Attribute Details
Returns the value of attribute format.
18
19
20
|
# File 'lib/ant/server/response.rb', line 18
def format
@format
end
|
.logger ⇒ Object
Returns the value of attribute logger.
18
19
20
|
# File 'lib/ant/server/response.rb', line 18
def logger
@logger
end
|
Class Method Details
24
25
26
|
# File 'lib/ant/server/response.rb', line 24
def format_mode(mode)
@format = resource(:formats, mode)
end
|
.log_mode(mode) ⇒ Object
20
21
22
|
# File 'lib/ant/server/response.rb', line 20
def log_mode(mode)
@logger = resource(:loggers, mode)
end
|
.recover_from!(exception_class, level) ⇒ Object
28
29
30
|
# File 'lib/ant/server/response.rb', line 28
def recover_from!(exception_class, level)
register(:exceptions, exception_class, level)
end
|
Instance Method Details
#exception_handler(exception) ⇒ Object
43
44
45
46
47
48
|
# File 'lib/ant/server/response.rb', line 43
def exception_handler(exception)
Server::Response.resources(:exceptions).each do |klass, recover|
return recover if exception.is_a?(klass)
end
exception.is_a?(StandardError) ? :fatal : nil
end
|
#handle(resolver, data) ⇒ Object
#process_request ⇒ Object
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
# File 'lib/ant/server/response.rb', line 60
def process_request
data = RequestResponse.new(request: request, params: params)
resolver = :success
Server::Response.logger.access(data)
begin
raise(AntError, 'No implementation given') unless block_given?
data.result = yield
rescue Exception => ex
data.exception = ex
resolver = exception_handler(ex)
end
handle(resolver, data)
end
|