Class: Simple::Httpd::App

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/simple/httpd/app.rb,
lib/simple/httpd/app.rb

Overview

The Simple::Httpd::App implements a Rack compatible app, which serves HTTP requests via a set of controllers inherited from a base controller class.

The individual routes are determined from the controller class names: assuming we have a controller class Foo::Bar::BazController inheriting from Foo::BaseController will serve the /bar/baz routes.

Additional static routes can be configured by calling “mount_directory!!” on the app object.

Defined Under Namespace

Classes: FileServer

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base_controller, logger:) ⇒ App

Builds a App object



24
25
26
27
28
29
30
31
32
# File 'lib/simple/httpd/app.rb', line 24

def initialize(base_controller, logger:)
  raise unless logger

  @base_controller = base_controller
  @logger = logger
  @file_mounts = []

  @app = Rack::URLMap.new(controllers_url_map)
end

Instance Attribute Details

#loggerObject (readonly)

Returns the value of attribute logger.



20
21
22
# File 'lib/simple/httpd/app.rb', line 20

def logger
  @logger
end

Instance Method Details

#mount_directory!(url:, path:) ⇒ Object



34
35
36
37
# File 'lib/simple/httpd/app.rb', line 34

def mount_directory!(url:, path:)
  @logger.debug "#{path}: mount directory #{path}"
  @app = FileServer.new(@app, url_prefix: url, root: path)
end