class Cramp::Abstract
Public Class Methods
call(env)
click to toggle source
# File lib/cramp/abstract.rb, line 12 def call(env) new(env).process end
new(env)
click to toggle source
# File lib/cramp/abstract.rb, line 17 def initialize(env) @env = env @finished = false @_state = :init end
Public Instance Methods
process()
click to toggle source
# File lib/cramp/abstract.rb, line 24 def process EM.next_tick { before_start } throw :async end
Private Instance Methods
build_headers()
click to toggle source
# File lib/cramp/abstract.rb, line 46 def build_headers status, headers = respond_to?(:respond_with, true) ? respond_with.dup : [200, {'Content-Type' => 'text/html'}] headers['Connection'] ||= 'keep-alive' [status, headers] end
continue()
click to toggle source
# File lib/cramp/abstract.rb, line 31 def continue init_async_body send_headers @_state = :started EM.next_tick { on_start } end
finish()
click to toggle source
# File lib/cramp/abstract.rb, line 65 def finish @_state = :finishing @body.succeed if is_finishable? ensure @_state = :finished @finished = true end
finished?()
click to toggle source
# File lib/cramp/abstract.rb, line 61 def finished? !!@finished end
halt(status, headers = {}, halt_body = '')
click to toggle source
# File lib/cramp/abstract.rb, line 77 def halt(status, headers = {}, halt_body = '') send_response(status, headers, [halt_body]) end
init_async_body()
click to toggle source
# File lib/cramp/abstract.rb, line 52 def init_async_body @body = Body.new if self.class.on_finish_callbacks.any? @body.callback { on_finish } @body.errback { on_finish } end end
is_finishable?()
click to toggle source
# File lib/cramp/abstract.rb, line 97 def is_finishable? !finished? && @body && !@body.closed? end
params()
click to toggle source
# File lib/cramp/abstract.rb, line 89 def params @params ||= request.params.update(route_params).symbolize_keys end
request()
click to toggle source
# File lib/cramp/abstract.rb, line 85 def request @request ||= Rack::Request.new(@env) end
route_params()
click to toggle source
# File lib/cramp/abstract.rb, line 93 def route_params @env['router.params'] || {} end
send_headers()
click to toggle source
# File lib/cramp/abstract.rb, line 39 def send_headers status, headers = build_headers send_initial_response(status, headers, @body) rescue StandardError, LoadError, SyntaxError => exception handle_exception(exception) end
send_initial_response(response_status, response_headers, response_body)
click to toggle source
# File lib/cramp/abstract.rb, line 73 def send_initial_response(response_status, response_headers, response_body) send_response(response_status, response_headers, response_body) end
send_response(response_status, response_headers, response_body)
click to toggle source
# File lib/cramp/abstract.rb, line 81 def send_response(response_status, response_headers, response_body) @env['async.callback'].call [response_status, response_headers, response_body] end