Module: Lively::Environment::Application
- Includes:
- Middleware
- Defined in:
- lib/lively/environment/application.rb
Overview
Multiplexing environment for Lively applications.
Declares the transport selection as explicit, overridable evaluator keys and uses ‘make_service` to compose the appropriate child environment at service startup time. This keeps transport selection in the service layer rather than in module inclusion hooks.
The ‘htty` key controls which transport is used. Override it in a service block to force a specific transport regardless of the environment variable:
~~~ ruby service “myapp” do
include Lively::Environment::Application
def htty = false # always use HTTP
end ~~~
Instance Method Summary collapse
-
#http_environment ⇒ Object
The environment module to use for HTTP transport.
-
#htty ⇒ Object
Whether to use HTTY transport.
-
#htty_environment ⇒ Object
The environment module to use for HTTY transport.
-
#make_service(environment) ⇒ Object
Build the service by composing the transport environment on top of this one.
-
#transport_environment ⇒ Object
The environment module for the selected transport.
Methods included from Middleware
#application, #middleware, #root
Instance Method Details
#http_environment ⇒ Object
The environment module to use for HTTP transport.
46 47 48 |
# File 'lib/lively/environment/application.rb', line 46 def http_environment Lively::Environment::HTTP end |
#htty ⇒ Object
Whether to use HTTY transport. Reads ENV by default.
34 35 36 |
# File 'lib/lively/environment/application.rb', line 34 def htty ENV["HTTY"] == "1" end |
#htty_environment ⇒ Object
The environment module to use for HTTY transport.
40 41 42 |
# File 'lib/lively/environment/application.rb', line 40 def htty_environment Lively::Environment::HTTY end |
#make_service(environment) ⇒ Object
Build the service by composing the transport environment on top of this one. Called by Async::Service::Generic.wrap — self is the evaluator at call time.
60 61 62 63 64 65 66 |
# File 'lib/lively/environment/application.rb', line 60 def make_service(environment) combined = environment.with(transport_environment) combined_evaluator = combined.evaluator # Call `service_class.new` directly rather than `Async::Service::Generic.wrap` — the combined evaluator still has `Application` (and therefore `make_service`) in its ancestor chain, so `wrap` would recurse back into this method. return combined_evaluator.service_class.new(combined, combined_evaluator) end |
#transport_environment ⇒ Object
The environment module for the selected transport.
52 53 54 |
# File 'lib/lively/environment/application.rb', line 52 def transport_environment htty ? htty_environment : http_environment end |