Class: RackDwsRegistry

Inherits:
Object
  • Object
show all
Includes:
AppRoutes
Defined in:
lib/rack_dwsregistry.rb

Instance Method Summary collapse

Constructor Details

#initialize(host: 'localhost', port: '59500') ⇒ RackDwsRegistry

Returns a new instance of RackDwsRegistry.



16
17
18
19
20
21
22
23
# File 'lib/rack_dwsregistry.rb', line 16

def initialize(host: 'localhost', port: '59500')
  
  super() # required for app-routes initialize method to exectue
  DRb.start_service

  # attach to the DRb server via a URI given on the command line
  @reg = DRbObject.new nil, "druby://#{host}:#{port}"
end

Instance Method Details

#call(env) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/rack_dwsregistry.rb', line 25

def call(env)
  
  @env = env
  request = env['REQUEST_URI'][/https?:\/\/[^\/]+(.*)/,1]

  req = Rack::Request.new(env)

  default_routes(env, req.params)
  content, content_type = run_route(request, env['REQUEST_METHOD'])

  error = $!

  page_content, status_code = if error then
    [error, 500]
  elsif content.nil? then
    ["404: page not found", 404]
  else
    [content, 200]
  end
  
  content_type ||= 'text/html'
  
  [status_code, {"Content-Type" => content_type}, [page_content]]

end