Class: Waw::Kern::App

Inherits:
Object show all
Includes:
Rack::Delegator, FreezedState, Hooks, Lifecycle, LivingState, Utils
Defined in:
lib/waw/kern/app.rb

Overview

Kernel waw application

Instance Attribute Summary

Attributes included from FreezedState

#app, #config, #deploy_words, #logger, #resources, #root_folder, #routing

Instance Method Summary collapse

Methods included from Lifecycle

#autoload, #load_application, #load_config, #load_deploy, #load_logger, #load_resources, #load_routing, #reload, #unload

Methods included from Utils

#find_web_root

Methods included from Hooks

#add_start_hook, #add_unload_hook, #execute_hooks, #hooks

Methods included from LivingState

#clean_living_state, #install_living_state, #params, #rack_env, #real_session, #request, #response, #session, #waw_state

Methods included from Rack::Delegator

#_visit, #delegate, #find_rack_app, #find_url_of, #has_delegate?, #is_delegate?, #visit

Constructor Details

#initialize(identifier = nil, options = {}) ⇒ App

Creates a kernel application instance



13
14
15
# File 'lib/waw/kern/app.rb', line 13

def initialize(identifier = nil, options = {})
  @options = options
end

Instance Method Details

#call(env) ⇒ Object

Installs the environment and delegates to the business application



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/waw/kern/app.rb', line 19

def call(env)
  install_living_state(env)
  if app=self.app
    app.call(env)
  else
    [503, {'Content-Type' => 'text/plain'}, ['This waw application is unloaded']]
  end
rescue ::WLang::Error => ex
  # On exception, returns a 500 with a message
  logger.error("Fatal error #{ex.message}")
  logger.error(ex.wlang_backtrace.join("\n"))
  logger.error(ex.backtrace.join("\n"))
  [500, {'Content-Type' => 'text/plain'}, ['500 Internal Server Error']]
rescue Exception => ex
  # On exception, returns a 500 with a message
  logger.error("Fatal error #{ex.message}")
  logger.error(ex.backtrace.join("\n"))
  [500, {'Content-Type' => 'text/plain'}, ['500 Internal Server Error']]
ensure
  clean_living_state
end

#identifierObject

Returns an identifier for this kernel application



42
43
44
# File 'lib/waw/kern/app.rb', line 42

def identifier
  @identifier || "No identifier (#{root_folder}/#{routing})"
end