Class: WebSystem::RequestPanel

Inherits:
Liza::Panel show all
Defined in:
lib/web_system/sub/request/request_panel.rb

Instance Attribute Summary

Attributes inherited from Liza::Panel

#key

Instance Method Summary collapse

Methods inherited from Liza::Panel

box, #box, color, #controller, controller, division, #division, #initialize, #push, #short, #started, subsystem, #subsystem, token

Methods inherited from Liza::Unit

const_missing, division, part, system, #system, test_class

Constructor Details

This class inherits a constructor from Liza::Panel

Instance Method Details

#_format(env, ret) ⇒ Object



46
47
48
49
50
51
52
# File 'lib/web_system/sub/request/request_panel.rb', line 46

def _format env, ret
  format = env["LIZA_FORMAT"]

  body = ret[2][0]
  body = DevBox.format format, body
  ret[2][0] = body
end

#_prepare(env) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/web_system/sub/request/request_panel.rb', line 54

def _prepare env
  log "#{env["REQUEST_METHOD"]} #{env["PATH_INFO"]}"

  path = env["PATH_INFO"]

  path, _sep, format = path.lpartition "."
  format = "html" if format.empty?

  segments = Array path.split("/")[1..-1]

  env["LIZA_PATH"]     = path
  env["LIZA_FORMAT"]   = format
  env["LIZA_SEGMENTS"] = segments
end

#call(env, allow_raise: false) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/web_system/sub/request/request_panel.rb', line 3

def call env, allow_raise: false
  t = Time.now
  request_klass = find env
  ret = request_klass.call env
  _format env, ret
  log "#{ret[0]} with #{ret[2].first.size} bytes in #{t.diff}s"
  ret
rescue => e
  raise e if allow_raise
  request_klass = WebSystem::ServerErrorRequest
  env["LIZA_ERROR"] = e

  ret = request_klass.call env
  log "#{ret[0]} with #{ret[2].first.size} bytes in #{t.diff}s"
  puts
  ret
end

#call!(env) ⇒ Object



21
22
23
# File 'lib/web_system/sub/request/request_panel.rb', line 21

def call! env
  call env, allow_raise: true
end

#find(env) ⇒ Object



38
39
40
41
42
# File 'lib/web_system/sub/request/request_panel.rb', line 38

def find env
  _prepare env

  routers.values.first.call(env)
end

#router(name, &block) ⇒ Object



27
28
29
30
# File 'lib/web_system/sub/request/request_panel.rb', line 27

def router(name, &block)
  router = routers[name] ||= Liza.const "#{name}_router_request"
  router.instance_eval(&block) if block_given?
end

#routersObject



32
33
34
# File 'lib/web_system/sub/request/request_panel.rb', line 32

def routers
  @routers ||= {}
end