LivelySourceLivelyEnvironmentApplication

module Application

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:

service "myapp" do
  include Lively::Environment::Application
  def htty = false  # always use HTTP
end

Definitions

def htty

Whether to use HTTY transport. Reads ENV["HTTY"] by default.

Signature

returns Boolean

Implementation

def htty
	ENV["HTTY"] == "1"
end

def htty_environment

The environment module to use for HTTY transport.

Signature

returns Module

Implementation

def htty_environment
	Lively::Environment::HTTY
end

def http_environment

The environment module to use for HTTP transport.

Signature

returns Module

Implementation

def http_environment
	Lively::Environment::HTTP
end

def transport_environment

The environment module for the selected transport.

Signature

returns Module

Implementation

def transport_environment
	htty ? htty_environment : http_environment
end

def make_service(environment)

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.

Signature

parameter environment Async::Service::Environment
returns Async::Service::Generic

Implementation

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