Class: Ramaze::Adapter::Base
Overview
This class is holding common behaviour for its subclasses.
Class Attribute Summary collapse
-
.thread ⇒ Object
readonly
Returns the value of attribute thread.
Class Method Summary collapse
-
.before_call(env) ⇒ Object
Tries to find the block assigned by #before and calls it, logs and raises again any errors encountered during this process.
-
.call(env) ⇒ Object
This is called by Rack with the usual env, subsequently calls ::respond with it.
- .join ⇒ Object
-
.respond(env) ⇒ Object
Initializes Request with env and an empty Response.
-
.shutdown ⇒ Object
Does nothing by default.
-
.start(host = nil, port = nil) ⇒ Object
Call ::startup with the given host and port.
Class Attribute Details
.thread ⇒ Object (readonly)
Returns the value of attribute thread.
50 51 52 |
# File 'lib/ramaze/adapter/base.rb', line 50 def thread @thread end |
Class Method Details
.before_call(env) ⇒ Object
Tries to find the block assigned by #before and calls it, logs and raises again any errors encountered during this process.
85 86 87 88 89 90 91 92 93 94 |
# File 'lib/ramaze/adapter/base.rb', line 85 def before_call env if Adapter.before begin Adapter.before.call(env) rescue Object => e Ramaze::Log.error e raise e end end end |
.call(env) ⇒ Object
This is called by Rack with the usual env, subsequently calls ::respond with it.
The method itself acts just as a wrapper for benchmarking and then calls .finish on the current response after ::respond has finished.
102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/ramaze/adapter/base.rb', line 102 def call(env) if returned = before_call(env) returned elsif Global.benchmarking require 'benchmark' time = Benchmark.measure{ returned = respond(env) } Log.debug('request took %.5fs [~%.0f r/s]' % [time.real, 1.0/time.real]) returned else respond(env) end end |
.join ⇒ Object
78 79 80 |
# File 'lib/ramaze/adapter/base.rb', line 78 def join @thread.join end |
.respond(env) ⇒ Object
Initializes Request with env and an empty Response. Records the request into Ramaze::Record if Global.record is true. Then goes on and calls Dispatcher::handle with request and response.
119 120 121 122 123 |
# File 'lib/ramaze/adapter/base.rb', line 119 def respond(env) Ramaze::STATE.wrap do Adapter::middleware.call(env) end end |
.shutdown ⇒ Object
Does nothing by default
69 70 71 72 73 74 75 76 |
# File 'lib/ramaze/adapter/base.rb', line 69 def shutdown if @server.respond_to?(:stop) Log.dev "Stopping @server" @server.stop else Log.dev "Cannot stop @server, skipping this step." end end |
.start(host = nil, port = nil) ⇒ Object
Call ::startup with the given host and port. Sets Global.server to itself. Adds a trap that is triggered by the value of Global.shutdown_trap, which is SIGINT by default.
57 58 59 60 61 62 63 64 65 |
# File 'lib/ramaze/adapter/base.rb', line 57 def start(host = nil, port = nil) @thread = startup(host, port) Global.server = self trap(Global.shutdown_trap){ trap(Global.shutdown_trap){ exit! } exit } end |