Class: Simple::Httpd
- Inherits:
-
Object
- Object
- Simple::Httpd
- Extended by:
- Forwardable
- Defined in:
- lib/simple/httpd/server.rb,
lib/simple/httpd.rb,
lib/simple/httpd.rb,
lib/simple/httpd/cli.rb,
lib/simple/httpd/version.rb
Overview
rubocop:disable Metrics/PerceivedComplexity, Metrics/AbcSize
Defined Under Namespace
Modules: CLI, GemHelper, Helpers, Mount, Rack, Reloader, RouteDescriptions, Server, ServiceIntegration Classes: BaseController, Route
Constant Summary collapse
- SELF =
self- VERSION =
GemHelper.version "postjob"
Class Attribute Summary collapse
-
.env ⇒ Object
Returns the value of attribute env.
Class Method Summary collapse
-
.build(*mounts) ⇒ Object
Converts the passed in arguments into a Simple::Httpd application.
- .custom_logger? ⇒ Boolean
-
.listen!(*mounts, environment: "development", host: nil, port:, &block) ⇒ Object
Converts the passed in args into a Simple::Httpd application.
-
.logger ⇒ Object
returns a logger for Simple::Httpd.
- .logger=(logger) ⇒ Object
Instance Method Summary collapse
-
#mount(mount, at: nil) ⇒ Object
Adds one or more mount_points.
- #rack ⇒ Object
- #route_descriptions ⇒ Object
Class Attribute Details
.env ⇒ Object
Returns the value of attribute env.
10 11 12 |
# File 'lib/simple/httpd.rb', line 10 def env @env end |
Class Method Details
.build(*mounts) ⇒ Object
Converts the passed in arguments into a Simple::Httpd application.
For a description of mounts see #add
73 74 75 |
# File 'lib/simple/httpd.rb', line 73 def self.build(*mounts) new(*mounts) end |
.custom_logger? ⇒ Boolean
24 25 26 |
# File 'lib/simple/httpd.rb', line 24 def self.custom_logger? @logger && @logger != ::Simple::CLI.logger end |
.listen!(*mounts, environment: "development", host: nil, port:, &block) ⇒ Object
Converts the passed in args into a Simple::Httpd application.
The passed in arguments are used to create a Simple::Httpd object. If the function receives a rack app (determined by the ability to respond to call/3) it redirects to Server.listen! right away - this way this method can be used as a helper method to easily start a Rack server.
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/simple/httpd.rb', line 52 def self.listen!(*mounts, environment: "development", host: nil, port:, &block) # If there is no argument but a block use the block as a rack server if block raise ArgumentError, "Can't deal w/block *and* mounts" unless mounts.empty? app = block elsif mounts.length == 1 && mounts.first.respond_to?(:call) # there is one argument, and that looks like a Rack app: return that. app = mounts.first else # Build a Httpd app, and listen app = build(*mounts) app.rack end Server.listen!(app, environment: environment, host: host, port: port) end |
.logger ⇒ Object
returns a logger for Simple::Httpd.
Initially we default to ::Simple::CLI.logger. This gives colored logging during loading and mounting. Note that Simple::Httpd::Server builds its own logger instance to to pass that along to the web server.
20 21 22 |
# File 'lib/simple/httpd.rb', line 20 def self.logger @logger ||= ::Simple::CLI.logger end |
.logger=(logger) ⇒ Object
28 29 30 |
# File 'lib/simple/httpd.rb', line 28 def self.logger=(logger) @logger = logger end |
Instance Method Details
#mount(mount, at: nil) ⇒ Object
Adds one or more mount_points
Each entry in mounts can be either:
-
a mount_point
[ mount_point, path ], e.g.[ "path/to/root", "/"] -
a string denoting a mount_point, e.g. “path/to/root:/”)
-
a string denoting a “/” mount_point (e.g. “path”, which is shorthand for “path:/”)
103 104 105 106 107 |
# File 'lib/simple/httpd.rb', line 103 def mount(mount, at: nil) raise ArgumentError, "Cannot mount onto an already built app" if built? @mounts << Mount.build(mount, at: at) end |
#rack ⇒ Object
112 113 114 |
# File 'lib/simple/httpd.rb', line 112 def rack @rack ||= build_rack end |
#route_descriptions ⇒ Object
89 90 91 92 93 |
# File 'lib/simple/httpd.rb', line 89 def route_descriptions @mounts.inject([]) do |ary, mount| ary.concat mount.route_descriptions end end |