# frozen_string_literal: true# Released under the MIT License.# Copyright, 2019-2024, by Samuel Williams.# Copyright, 2019, by Sho Ito.require'async/service'moduleFalcon# Manages environments which describes how to host a specific application.## Environments are key-value maps with lazy value resolution. An environment can inherit from a parent environment, which can provide defaults## A typical configuration file might look something like:## ~~~ ruby# #!/usr/bin/env falcon-host# # frozen_string_literal: true# # load :rack, :self_signed_tls, :supervisor# # supervisor# # rack 'hello.localhost', :self_signed_tls do# end# ~~~#classConfiguration<::Async::Service::Configuration# Load the specified configuration file. See {Loader#load_file} for more details.defload_file(path)Loader.load_file(self,path)end# The domain specific language for loading configuration files.classLoader<::Async::Service::Loader# Load specific features into the current configuration.## @deprecated Use `require` instead.# @parameter features [Array(Symbol)] The features to load.defload(*features)features.eachdo|feature|casefeaturewhenSymbolrequireFile.join(__dir__,"environment","#{feature}.rb")elseraiseLoadError,"Unsure about how to load #{feature}!"endendend# Define a host with the specified name.# Adds `root` and `authority` keys.# @deprecated Use `service` and `include Falcon::Environment::Server` instead.# @parameter name [String] The name of the environment, usually a hostname.defhost(name,*parents,&block)@configuration.add(merge(*parents,name: name,root: @root,authority: name,&block))end# Define a proxy with the specified name.# Adds `root` and `authority` keys.# @deprecated Use `service` and `include Falcon::Environment::Proxy` instead.# @parameter name [String] The name of the environment, usually a hostname.defproxy(name,*parents,&block)@configuration.add(merge(:proxy,*parents,name: name,root: @root,authority: name,&block))end# Define a rack application with the specified name.# Adds `root` and `authority` keys.# @deprecated Use `service` and `include Falcon::Environment::Rack` instead.# @parameter name [String] The name of the environment, usually a hostname.defrack(name,*parents,&block)@configuration.add(merge(:rack,*parents,name: name,root: @root,authority: name,&block))end# Define a supervisor instance# @deprecated Use `service` and `include Falcon::Environment::Supervisor` instead.defsupervisor(&block)name=File.join(@root,"supervisor")@configuration.add(merge(:supervisor,name: name,root: @root,&block))endprivate# Build a new environment with the specified name and the given parents.# @parameter name [String]# @parameter parents [Array(Symbol)]# @yields {...} The block that will generate the environment.defmerge(*parents,**initial,&block)facets=parents.map{|parent|Environment::LEGACY_ENVIRONMENTS.fetch(parent)}::Async::Service::Environment.build(*facets,**initial,&block)endendendend