Class: Simple::Httpd
- Inherits:
-
Object
- Object
- Simple::Httpd
- Extended by:
- Forwardable
- Defined in:
- lib/simple/httpd.rb,
lib/simple/httpd.rb,
lib/simple/httpd/cli.rb,
lib/simple/httpd/server.rb,
lib/simple/httpd/version.rb
Defined Under Namespace
Modules: CLI, GemHelper, Helpers, Rack, Server Classes: BaseController, MountSpec, Service
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(*mount_specs) ⇒ Object
Converts the passed in arguments into a Simple::Httpd application.
-
.listen!(*mount_specs, environment: "development", host: nil, port:, logger: nil, &block) ⇒ Object
Converts the passed in args into a Simple::Httpd application.
- .logger ⇒ Object
- .logger=(logger) ⇒ Object
Instance Method Summary collapse
- #listen!(environment:, port:, logger:) ⇒ Object
-
#mount(mount_spec, at: nil) ⇒ Object
Adds one or more mount_points.
- #rack ⇒ Object
Class Attribute Details
.env ⇒ Object
Returns the value of attribute env.
6 7 8 |
# File 'lib/simple/httpd/cli.rb', line 6 def env @env end |
Class Method Details
.build(*mount_specs) ⇒ Object
Converts the passed in arguments into a Simple::Httpd application.
For a description of mounts see #add
58 59 60 |
# File 'lib/simple/httpd.rb', line 58 def self.build(*mount_specs) new(*mount_specs) end |
.listen!(*mount_specs, environment: "development", host: nil, port:, logger: nil, &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.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/simple/httpd.rb', line 37 def self.listen!(*mount_specs, environment: "development", host: nil, port:, logger: nil, &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* mount_specs" unless mount_specs.empty? app = block elsif mount_specs.length == 1 && mount_specs.first.respond_to?(:call) # there is one argument, and that looks like a Rack app: return that. app = mount_specs.first else # Build a Httpd app, and listen app = build(*mount_specs) app.rack end Server.listen!(app, environment: environment, host: host, port: port, logger: logger) end |
.logger ⇒ Object
26 27 28 |
# File 'lib/simple/httpd.rb', line 26 def self.logger @logger ||= ::Logger.new(STDERR, level: ::Logger::INFO) end |
.logger=(logger) ⇒ Object
22 23 24 |
# File 'lib/simple/httpd.rb', line 22 def self.logger=(logger) @logger = logger end |
Instance Method Details
#listen!(environment:, port:, logger:) ⇒ Object
114 115 116 |
# File 'lib/simple/httpd.rb', line 114 def listen!(environment:, port:, logger:) SELF.listen!(rack, environment: environment, port: port, logger: logger) end |
#mount(mount_spec, 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:/”)
82 83 84 85 86 |
# File 'lib/simple/httpd.rb', line 82 def mount(mount_spec, at: nil) raise ArgumentError, "Cannot mount onto an already built app" if built? @mount_specs << MountSpec.build(mount_spec, at: at) end |
#rack ⇒ Object
91 92 93 |
# File 'lib/simple/httpd.rb', line 91 def rack @rack ||= build_rack end |