module Skyline::Callbacks
Public Instance Methods
before_start(n = 0)
click to toggle source
# File lib/skyline/callbacks.rb, line 33 def before_start(n = 0) if callback = self.class.before_start_callbacks[n] callback_wrapper { send(callback) { before_start(n+1) } } else continue end end
callback_wrapper() { || ... }
click to toggle source
# File lib/skyline/callbacks.rb, line 55 def callback_wrapper EM.next_tick do begin yield rescue StandardError, LoadError, SyntaxError => exception handle_exception(exception) end end end
on_finish()
click to toggle source
# File lib/skyline/callbacks.rb, line 49 def on_finish self.class.on_finish_callbacks.each do |callback| callback_wrapper { send(callback) } end end
on_start()
click to toggle source
# File lib/skyline/callbacks.rb, line 41 def on_start callback_wrapper { start } if respond_to?(:start) self.class.on_start_callback.each do |callback| callback_wrapper { send(callback) unless @finished } end end
Protected Instance Methods
_invoke_data_callbacks(message)
click to toggle source
# File lib/skyline/callbacks.rb, line 67 def _invoke_data_callbacks(message) self.class.on_data_callbacks.each do |callback| callback_wrapper { send(callback, message) } end end
handle_exception(exception)
click to toggle source
# File lib/skyline/callbacks.rb, line 73 def handle_exception(exception) handler = ExceptionHandler.new(@env, exception) # Log the exception exception_body = handler.dump_exception Skyline.logger ? Skyline.logger.error(exception_body) : $stderr.puts(exception_body) case @_state when :init halt 500, {"Content-Type" => 'text/html'}, ENV['RACK_ENV'] == 'development' ? handler.pretty : 'Something went wrong' when :started halt 500, {"Content-Type" => 'text/html'}, ENV['RACK_ENV'] == 'development' ? handler.pretty : 'Something went wrong' else finish end end