falcon 0.43.0 → 0.44.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/changes.md +22 -0
- data/lib/falcon/command/host.rb +6 -32
- data/lib/falcon/command/proxy.rb +20 -15
- data/lib/falcon/command/redirect.rb +21 -15
- data/lib/falcon/command/serve.rb +41 -65
- data/lib/falcon/command/top.rb +1 -1
- data/lib/falcon/command/virtual.rb +15 -23
- data/lib/falcon/configuration.rb +26 -124
- data/lib/falcon/environment/application.rb +60 -0
- data/lib/falcon/environment/lets_encrypt_tls.rb +34 -0
- data/lib/falcon/environment/proxy.rb +109 -0
- data/lib/falcon/environment/rack.rb +20 -0
- data/lib/falcon/environment/rackup.rb +26 -0
- data/lib/falcon/environment/redirect.rb +50 -0
- data/lib/falcon/environment/self_signed_tls.rb +45 -0
- data/lib/falcon/environment/server.rb +69 -0
- data/lib/falcon/environment/supervisor.rb +40 -0
- data/lib/falcon/environment/tls.rb +97 -0
- data/lib/falcon/{environments.rb → environment.rb} +3 -4
- data/lib/falcon/service/server.rb +84 -0
- data/lib/falcon/service/supervisor.rb +4 -3
- data/lib/falcon/{controller → service}/virtual.rb +71 -18
- data/lib/falcon/version.rb +2 -2
- data/license.md +2 -0
- data.tar.gz.sig +0 -0
- metadata +24 -26
- metadata.gz.sig +0 -0
- data/lib/.DS_Store +0 -0
- data/lib/falcon/controller/host.rb +0 -55
- data/lib/falcon/controller/proxy.rb +0 -109
- data/lib/falcon/controller/redirect.rb +0 -59
- data/lib/falcon/controller/serve.rb +0 -110
- data/lib/falcon/environments/application.rb +0 -56
- data/lib/falcon/environments/lets_encrypt_tls.rb +0 -30
- data/lib/falcon/environments/proxy.rb +0 -22
- data/lib/falcon/environments/rack.rb +0 -33
- data/lib/falcon/environments/self_signed_tls.rb +0 -38
- data/lib/falcon/environments/supervisor.rb +0 -34
- data/lib/falcon/environments/tls.rb +0 -86
- data/lib/falcon/service/application.rb +0 -99
- data/lib/falcon/service/generic.rb +0 -61
- data/lib/falcon/service/proxy.rb +0 -49
- data/lib/falcon/services.rb +0 -82
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: deaf700b8a46f5af5e6e1151c0a0708789add0c2e66f4d6048e17da5e7da8c84
|
4
|
+
data.tar.gz: bac8d213a65f15c4bcc0741e86f357f1158ff2fedacb9480a00ce7ea3498de64
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 40c405c0e768f68b1a4c56cbf7f155571240b30e8079051243e354596e32db76593929352ca70799d13cedd0fa1fe13afbbfb54edf6d1b0cb0c65d3edf7ea349
|
7
|
+
data.tar.gz: 9a94416a4b3f82cc34fe61e5b0cf1bdc23ab6c2190ed37d95ff11a9cfb4dfee204c855245d03715cd0d5b63f439451200752240bca2dce58336adc8f84b0c422
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/changes.md
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# Changes
|
2
|
+
|
3
|
+
# v0.44.0
|
4
|
+
|
5
|
+
## Falcon Host
|
6
|
+
|
7
|
+
`async-service` is a new gem that exposes a generic service interface on top of `async-container`. Previously, `falcon host` used `async-container` directly and `build-environment` for configuration. In order to allow for more generic service definitions and configuration, `async-service` now provides a similar interface to `build-environment` and exposes this in a way that can be used for services other tha falcon. This makes it simpler to integrate multiple services into a single application.
|
8
|
+
|
9
|
+
The current configuration format uses definitions like this:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
rack 'hello.localhost', :self_signed_tls
|
13
|
+
```
|
14
|
+
|
15
|
+
This changes to:
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
service 'hello.localhost' do
|
19
|
+
include Falcon::Environment::Rack
|
20
|
+
include Falcon::Environment::SelfSignedTLS
|
21
|
+
end
|
22
|
+
```
|
data/lib/falcon/command/host.rb
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# Released under the MIT License.
|
4
|
-
# Copyright, 2019-
|
4
|
+
# Copyright, 2019-2024, by Samuel Williams.
|
5
5
|
|
6
|
-
require_relative '
|
7
|
-
require_relative '../configuration'
|
6
|
+
require_relative 'paths'
|
8
7
|
require_relative '../version'
|
9
8
|
|
10
9
|
require 'samovar'
|
11
|
-
require '
|
10
|
+
require 'async/service/controller'
|
12
11
|
|
13
12
|
module Falcon
|
14
13
|
module Command
|
@@ -23,28 +22,13 @@ module Falcon
|
|
23
22
|
# @attribute [Array(String)]
|
24
23
|
many :paths, "Service configuration paths.", default: ["falcon.rb"]
|
25
24
|
|
25
|
+
include Paths
|
26
|
+
|
26
27
|
# The container class to use.
|
27
28
|
def container_class
|
28
29
|
Async::Container.best_container_class
|
29
30
|
end
|
30
31
|
|
31
|
-
# Generate a configuration based on the specified {paths}.
|
32
|
-
def configuration
|
33
|
-
configuration = Configuration.new
|
34
|
-
|
35
|
-
@paths.each do |path|
|
36
|
-
path = File.expand_path(path)
|
37
|
-
configuration.load_file(path)
|
38
|
-
end
|
39
|
-
|
40
|
-
return configuration
|
41
|
-
end
|
42
|
-
|
43
|
-
# Prepare a new controller for the command.
|
44
|
-
def controller
|
45
|
-
Controller::Host.new(self)
|
46
|
-
end
|
47
|
-
|
48
32
|
# Prepare the environment and run the controller.
|
49
33
|
def call
|
50
34
|
Console.logger.info(self) do |buffer|
|
@@ -54,17 +38,7 @@ module Falcon
|
|
54
38
|
buffer.puts "- To reload: kill -HUP #{Process.pid}"
|
55
39
|
end
|
56
40
|
|
57
|
-
|
58
|
-
Bundler.require(:preload)
|
59
|
-
rescue Bundler::GemfileNotFound
|
60
|
-
# Ignore.
|
61
|
-
end
|
62
|
-
|
63
|
-
if GC.respond_to?(:compact)
|
64
|
-
GC.compact
|
65
|
-
end
|
66
|
-
|
67
|
-
self.controller.run
|
41
|
+
Async::Service::Controller.run(self.configuration, container_class: self.container_class)
|
68
42
|
end
|
69
43
|
end
|
70
44
|
end
|
data/lib/falcon/command/proxy.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# Released under the MIT License.
|
4
|
-
# Copyright, 2020-
|
4
|
+
# Copyright, 2020-2024, by Samuel Williams.
|
5
5
|
|
6
|
-
require_relative '../
|
6
|
+
require_relative '../environment/proxy'
|
7
7
|
require_relative 'paths'
|
8
8
|
|
9
9
|
require 'samovar'
|
@@ -31,20 +31,21 @@ module Falcon
|
|
31
31
|
|
32
32
|
include Paths
|
33
33
|
|
34
|
-
|
35
|
-
|
36
|
-
|
34
|
+
def environment(**options)
|
35
|
+
Async::Service::Environment.new(Falcon::Environment::Proxy).with(
|
36
|
+
root: Dir.pwd,
|
37
|
+
name: self.class.name,
|
38
|
+
verbose: self.parent&.verbose?,
|
39
|
+
url: @options[:bind],
|
40
|
+
timeout: @options[:timeout],
|
41
|
+
**options
|
42
|
+
)
|
37
43
|
end
|
38
44
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
# Options for the container.
|
45
|
-
# See {Controller::Serve#setup}.
|
46
|
-
def container_options
|
47
|
-
{}
|
45
|
+
def configuration
|
46
|
+
Configuration.for(
|
47
|
+
self.environment(environments: super.environments)
|
48
|
+
)
|
48
49
|
end
|
49
50
|
|
50
51
|
# Prepare the environment and run the controller.
|
@@ -54,9 +55,13 @@ module Falcon
|
|
54
55
|
buffer.puts "- Binding to: #{@options[:bind]}"
|
55
56
|
buffer.puts "- To terminate: Ctrl-C or kill #{Process.pid}"
|
56
57
|
buffer.puts "- To reload: kill -HUP #{Process.pid}"
|
58
|
+
|
59
|
+
self.resolved_paths.each do |path|
|
60
|
+
buffer.puts "- Loading configuration from #{path}"
|
61
|
+
end
|
57
62
|
end
|
58
63
|
|
59
|
-
self.
|
64
|
+
Async::Service::Controller.run(self.configuration)
|
60
65
|
end
|
61
66
|
|
62
67
|
# The endpoint to bind to.
|
@@ -1,9 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# Released under the MIT License.
|
4
|
-
# Copyright, 2020-
|
4
|
+
# Copyright, 2020-2024, by Samuel Williams.
|
5
5
|
|
6
|
-
require_relative '../
|
6
|
+
require_relative '../environment/redirect'
|
7
7
|
require_relative 'paths'
|
8
8
|
|
9
9
|
require 'samovar'
|
@@ -29,20 +29,22 @@ module Falcon
|
|
29
29
|
|
30
30
|
include Paths
|
31
31
|
|
32
|
-
|
33
|
-
|
34
|
-
|
32
|
+
def environment(**options)
|
33
|
+
Async::Service::Environment.new(Falcon::Environment::Redirect).with(
|
34
|
+
root: Dir.pwd,
|
35
|
+
name: self.class.name,
|
36
|
+
verbose: self.parent&.verbose?,
|
37
|
+
url: @options[:bind],
|
38
|
+
redirect_url: @options[:redirect],
|
39
|
+
timeout: @options[:timeout],
|
40
|
+
**options
|
41
|
+
)
|
35
42
|
end
|
36
43
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
# Options for the container.
|
43
|
-
# See {Controller::Serve#setup}.
|
44
|
-
def container_options
|
45
|
-
{}
|
44
|
+
def configuration
|
45
|
+
Configuration.for(
|
46
|
+
self.environment(environments: super.environments)
|
47
|
+
)
|
46
48
|
end
|
47
49
|
|
48
50
|
# Prepare the environment and run the controller.
|
@@ -52,9 +54,13 @@ module Falcon
|
|
52
54
|
buffer.puts "- Binding to: #{@options[:bind]}"
|
53
55
|
buffer.puts "- To terminate: Ctrl-C or kill #{Process.pid}"
|
54
56
|
buffer.puts "- To reload: kill -HUP #{Process.pid}"
|
57
|
+
|
58
|
+
self.resolved_paths.each do |path|
|
59
|
+
buffer.puts "- Loading configuration from #{path}"
|
60
|
+
end
|
55
61
|
end
|
56
62
|
|
57
|
-
self.
|
63
|
+
Async::Service::Controller.run(self.configuration)
|
58
64
|
end
|
59
65
|
|
60
66
|
# The endpoint to bind to.
|
data/lib/falcon/command/serve.rb
CHANGED
@@ -1,28 +1,19 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# Released under the MIT License.
|
4
|
-
# Copyright, 2018-
|
4
|
+
# Copyright, 2018-2024, by Samuel Williams.
|
5
5
|
# Copyright, 2018, by Mitsutaka Mimura.
|
6
6
|
|
7
7
|
require_relative '../server'
|
8
8
|
require_relative '../endpoint'
|
9
|
-
require_relative '../
|
9
|
+
require_relative '../configuration'
|
10
|
+
require_relative '../service/server'
|
11
|
+
require_relative '../environment/rackup'
|
10
12
|
|
11
13
|
require 'async/container'
|
12
|
-
|
13
|
-
require 'async/io/trap'
|
14
|
-
require 'async/io/host_endpoint'
|
15
|
-
require 'async/io/shared_endpoint'
|
16
|
-
require 'async/io/ssl_endpoint'
|
17
|
-
|
18
14
|
require 'async/http/client'
|
19
|
-
|
20
15
|
require 'samovar'
|
21
16
|
|
22
|
-
require 'rack/builder'
|
23
|
-
|
24
|
-
require 'bundler'
|
25
|
-
|
26
17
|
module Falcon
|
27
18
|
module Command
|
28
19
|
# Implements the `falcon serve` command. Designed for *development*.
|
@@ -53,6 +44,42 @@ module Falcon
|
|
53
44
|
option '--threads <count>', "Number of threads (hybrid only).", type: Integer
|
54
45
|
end
|
55
46
|
|
47
|
+
def container_options
|
48
|
+
@options.slice(:count, :forks, :threads)
|
49
|
+
end
|
50
|
+
|
51
|
+
def endpoint_options
|
52
|
+
@options.slice(:hostname, :port, :timeout)
|
53
|
+
end
|
54
|
+
|
55
|
+
def environment
|
56
|
+
Async::Service::Environment.new(Falcon::Environment::Server).with(
|
57
|
+
Falcon::Environment::Rackup,
|
58
|
+
|
59
|
+
root: Dir.pwd,
|
60
|
+
|
61
|
+
verbose: self.parent&.verbose?,
|
62
|
+
cache: @options[:cache],
|
63
|
+
|
64
|
+
container_options: self.container_options,
|
65
|
+
endpoint_options: self.endpoint_options,
|
66
|
+
|
67
|
+
rackup_path: @options[:config],
|
68
|
+
preload: [@options[:preload]].compact,
|
69
|
+
url: @options[:bind],
|
70
|
+
|
71
|
+
name: "server",
|
72
|
+
|
73
|
+
endpoint: ->{Endpoint.parse(url, **endpoint_options)}
|
74
|
+
)
|
75
|
+
end
|
76
|
+
|
77
|
+
def configuration
|
78
|
+
Configuration.new.tap do |configuration|
|
79
|
+
configuration.add(self.environment)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
56
83
|
# The container class to use.
|
57
84
|
def container_class
|
58
85
|
case @options[:container]
|
@@ -65,37 +92,6 @@ module Falcon
|
|
65
92
|
end
|
66
93
|
end
|
67
94
|
|
68
|
-
# Whether verbose logging is enabled.
|
69
|
-
# @returns [Boolean]
|
70
|
-
def verbose?
|
71
|
-
@parent&.verbose?
|
72
|
-
end
|
73
|
-
|
74
|
-
# Whether to enable the application HTTP cache.
|
75
|
-
# @returns [Boolean]
|
76
|
-
def cache?
|
77
|
-
@options[:cache]
|
78
|
-
end
|
79
|
-
|
80
|
-
# Load the rack application from the specified configuration path.
|
81
|
-
# @returns [Protocol::HTTP::Middleware]
|
82
|
-
def load_app
|
83
|
-
rack_app, _ = Rack::Builder.parse_file(@options[:config])
|
84
|
-
|
85
|
-
return Server.middleware(rack_app, verbose: self.verbose?, cache: self.cache?)
|
86
|
-
end
|
87
|
-
|
88
|
-
# Options for the container.
|
89
|
-
# See {Controller::Serve#setup}.
|
90
|
-
def container_options
|
91
|
-
@options.slice(:count, :forks, :threads)
|
92
|
-
end
|
93
|
-
|
94
|
-
# Options for the {endpoint}.
|
95
|
-
def endpoint_options
|
96
|
-
@options.slice(:hostname, :port, :reuse_port, :timeout)
|
97
|
-
end
|
98
|
-
|
99
95
|
# The endpoint to bind to.
|
100
96
|
def endpoint
|
101
97
|
Endpoint.parse(@options[:bind], **endpoint_options)
|
@@ -111,11 +107,6 @@ module Falcon
|
|
111
107
|
Async::HTTP::Client.new(client_endpoint)
|
112
108
|
end
|
113
109
|
|
114
|
-
# Prepare a new controller for the command.
|
115
|
-
def controller
|
116
|
-
Controller::Serve.new(self)
|
117
|
-
end
|
118
|
-
|
119
110
|
# Prepare the environment and run the controller.
|
120
111
|
def call
|
121
112
|
Console.logger.info(self) do |buffer|
|
@@ -125,22 +116,7 @@ module Falcon
|
|
125
116
|
buffer.puts "- To reload configuration: kill -HUP #{Process.pid}"
|
126
117
|
end
|
127
118
|
|
128
|
-
|
129
|
-
full_path = File.expand_path(path)
|
130
|
-
load(full_path)
|
131
|
-
end
|
132
|
-
|
133
|
-
begin
|
134
|
-
Bundler.require(:preload)
|
135
|
-
rescue Bundler::GemfileNotFound
|
136
|
-
# Ignore.
|
137
|
-
end
|
138
|
-
|
139
|
-
if GC.respond_to?(:compact)
|
140
|
-
GC.compact
|
141
|
-
end
|
142
|
-
|
143
|
-
self.controller.run
|
119
|
+
Async::Service::Controller.run(self.configuration, container_class: self.container_class)
|
144
120
|
end
|
145
121
|
end
|
146
122
|
end
|
data/lib/falcon/command/top.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# Released under the MIT License.
|
4
|
-
# Copyright, 2018-
|
4
|
+
# Copyright, 2018-2024, by Samuel Williams.
|
5
5
|
|
6
|
-
require_relative '../
|
6
|
+
require_relative '../service/virtual'
|
7
7
|
require_relative 'paths'
|
8
8
|
|
9
9
|
require 'samovar'
|
@@ -30,26 +30,20 @@ module Falcon
|
|
30
30
|
# @attribute [Array(String)]
|
31
31
|
many :paths
|
32
32
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
def bind_secure
|
42
|
-
@options[:bind_secure]
|
33
|
+
def environment
|
34
|
+
Async::Service::Environment.new(Falcon::Service::Virtual::Environment).with(
|
35
|
+
verbose: self.parent&.verbose?,
|
36
|
+
configuration_paths: self.paths,
|
37
|
+
bind_insecure: @options[:bind_insecure],
|
38
|
+
bind_secure: @options[:bind_secure],
|
39
|
+
timeout: @options[:timeout],
|
40
|
+
)
|
43
41
|
end
|
44
42
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
# The connection timeout to use for incoming connections.
|
51
|
-
def timeout
|
52
|
-
@options[:timeout]
|
43
|
+
def configuration
|
44
|
+
Async::Service::Configuration.new.tap do |configuration|
|
45
|
+
configuration.add(self.environment)
|
46
|
+
end
|
53
47
|
end
|
54
48
|
|
55
49
|
# Prepare the environment and run the controller.
|
@@ -60,9 +54,7 @@ module Falcon
|
|
60
54
|
buffer.puts "- To reload all sites: kill -HUP #{Process.pid}"
|
61
55
|
end
|
62
56
|
|
63
|
-
|
64
|
-
|
65
|
-
self.controller.run
|
57
|
+
Async::Service::Controller.run(self.configuration)
|
66
58
|
end
|
67
59
|
|
68
60
|
# The insecure endpoint for connecting to the {Redirect} instance.
|
data/lib/falcon/configuration.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# Released under the MIT License.
|
4
|
-
# Copyright, 2019-
|
4
|
+
# Copyright, 2019-2024, by Samuel Williams.
|
5
5
|
# Copyright, 2019, by Sho Ito.
|
6
6
|
|
7
|
-
require '
|
7
|
+
require 'async/service'
|
8
8
|
|
9
9
|
module Falcon
|
10
10
|
# Manages environments which describes how to host a specific application.
|
@@ -25,177 +25,79 @@ module Falcon
|
|
25
25
|
# end
|
26
26
|
# ~~~
|
27
27
|
#
|
28
|
-
class Configuration
|
29
|
-
# Initialize an empty configuration.
|
30
|
-
def initialize
|
31
|
-
@environments = {}
|
32
|
-
end
|
33
|
-
|
34
|
-
# The map of named environments.
|
35
|
-
# @attribute [Hash(String, Build::Environment)]
|
36
|
-
attr :environments
|
37
|
-
|
38
|
-
# Enumerate all environments that have the specified key.
|
39
|
-
# @parameter key [Symbol] Filter environments that don't have this key.
|
40
|
-
def each(key = :authority)
|
41
|
-
return to_enum(key) unless block_given?
|
42
|
-
|
43
|
-
@environments.each do |name, environment|
|
44
|
-
environment = environment.flatten
|
45
|
-
|
46
|
-
if environment.include?(key)
|
47
|
-
yield environment
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
# Add the named environment to the configuration.
|
53
|
-
def add(environment)
|
54
|
-
name = environment.name
|
55
|
-
|
56
|
-
unless name
|
57
|
-
raise ArgumentError, "Environment name is nil #{environment.inspect}"
|
58
|
-
end
|
59
|
-
|
60
|
-
environment = environment.flatten
|
61
|
-
|
62
|
-
raise KeyError.new("#{name.inspect} is already set", key: name) if @environments.key?(name)
|
63
|
-
|
64
|
-
@environments[name] = environment
|
65
|
-
end
|
66
|
-
|
28
|
+
class Configuration < ::Async::Service::Configuration
|
67
29
|
# Load the specified configuration file. See {Loader#load_file} for more details.
|
68
30
|
def load_file(path)
|
69
31
|
Loader.load_file(self, path)
|
70
32
|
end
|
71
33
|
|
72
34
|
# The domain specific language for loading configuration files.
|
73
|
-
class Loader
|
74
|
-
# Initialize the loader, attached to a specific configuration instance.
|
75
|
-
# Any environments generated by the loader will be added to the configuration.
|
76
|
-
# @parameter configuration [Configuration]
|
77
|
-
# @parameter root [String] The file-system root path for relative path computations.
|
78
|
-
def initialize(configuration, root = nil)
|
79
|
-
@loaded = {}
|
80
|
-
@configuration = configuration
|
81
|
-
@environments = {}
|
82
|
-
@root = root
|
83
|
-
end
|
84
|
-
|
85
|
-
# The file-system root path which is injected into the environments as required.
|
86
|
-
# @attribute [String]
|
87
|
-
attr :root
|
88
|
-
|
89
|
-
# The attached configuration instance.
|
90
|
-
# @attribute [Configuration]
|
91
|
-
attr :configuration
|
92
|
-
|
93
|
-
# Load the specified file into the given configuration.
|
94
|
-
# @parameter configuration [Configuration]
|
95
|
-
# @oaram path [String] The path to the configuration file, e.g. `falcon.rb`.
|
96
|
-
def self.load_file(configuration, path)
|
97
|
-
path = File.realpath(path)
|
98
|
-
root = File.dirname(path)
|
99
|
-
|
100
|
-
loader = self.new(configuration, root)
|
101
|
-
|
102
|
-
loader.instance_eval(File.read(path), path)
|
103
|
-
end
|
104
|
-
|
35
|
+
class Loader < ::Async::Service::Loader
|
105
36
|
# Load specific features into the current configuration.
|
106
37
|
#
|
107
|
-
#
|
108
|
-
#
|
38
|
+
# @deprecated Use `require` instead.
|
109
39
|
# @parameter features [Array(Symbol)] The features to load.
|
110
40
|
def load(*features)
|
111
41
|
features.each do |feature|
|
112
|
-
next if @loaded.include?(feature)
|
113
|
-
|
114
42
|
case feature
|
115
43
|
when Symbol
|
116
|
-
|
117
|
-
|
118
|
-
self.instance_eval(File.read(relative_path), relative_path)
|
119
|
-
|
120
|
-
@loaded[feature] = relative_path
|
121
|
-
when Module
|
122
|
-
feature.load(self)
|
123
|
-
|
124
|
-
@loaded[feature] = feature
|
44
|
+
require File.join(__dir__, "environment", "#{feature}.rb")
|
125
45
|
else
|
126
46
|
raise LoadError, "Unsure about how to load #{feature}!"
|
127
47
|
end
|
128
48
|
end
|
129
49
|
end
|
130
50
|
|
131
|
-
# Add the named environment, with zero or more parent environments, defined using the specified `block`.
|
132
|
-
# @parameter name [String] The name of the environment.
|
133
|
-
# @parameter parents [Array(Symbol)] The names of the parent environments to inherit.
|
134
|
-
# @yields {...} The block that will generate the environment.
|
135
|
-
def environment(name, *parents, &block)
|
136
|
-
raise KeyError.new("#{name} is already set", key: name) if @environments.key?(name)
|
137
|
-
@environments[name] = merge(name, *parents, &block)
|
138
|
-
end
|
139
|
-
|
140
51
|
# Define a host with the specified name.
|
141
52
|
# Adds `root` and `authority` keys.
|
53
|
+
# @deprecated Use `service` and `include Falcon::Environment::Server` instead.
|
142
54
|
# @parameter name [String] The name of the environment, usually a hostname.
|
143
55
|
def host(name, *parents, &block)
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
environment[:authority] = name
|
148
|
-
|
149
|
-
@configuration.add(environment.flatten)
|
56
|
+
@configuration.add(
|
57
|
+
merge(*parents, name: name, root: @root, authority: name, &block)
|
58
|
+
)
|
150
59
|
end
|
151
60
|
|
152
61
|
# Define a proxy with the specified name.
|
153
62
|
# Adds `root` and `authority` keys.
|
63
|
+
# @deprecated Use `service` and `include Falcon::Environment::Proxy` instead.
|
154
64
|
# @parameter name [String] The name of the environment, usually a hostname.
|
155
65
|
def proxy(name, *parents, &block)
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
environment[:authority] = name
|
160
|
-
|
161
|
-
@configuration.add(environment.flatten)
|
66
|
+
@configuration.add(
|
67
|
+
merge(:proxy, *parents, name: name, root: @root, authority: name, &block)
|
68
|
+
)
|
162
69
|
end
|
163
70
|
|
164
71
|
# Define a rack application with the specified name.
|
165
72
|
# Adds `root` and `authority` keys.
|
73
|
+
# @deprecated Use `service` and `include Falcon::Environment::Rack` instead.
|
166
74
|
# @parameter name [String] The name of the environment, usually a hostname.
|
167
75
|
def rack(name, *parents, &block)
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
environment[:authority] = name
|
172
|
-
|
173
|
-
@configuration.add(environment.flatten)
|
76
|
+
@configuration.add(
|
77
|
+
merge(:rack, *parents, name: name, root: @root, authority: name, &block)
|
78
|
+
)
|
174
79
|
end
|
175
80
|
|
176
81
|
# Define a supervisor instance
|
177
|
-
#
|
82
|
+
# @deprecated Use `service` and `include Falcon::Environment::Supervisor` instead.
|
178
83
|
def supervisor(&block)
|
179
84
|
name = File.join(@root, "supervisor")
|
180
|
-
environment = merge(name, :supervisor, &block)
|
181
85
|
|
182
|
-
|
183
|
-
|
184
|
-
|
86
|
+
@configuration.add(
|
87
|
+
merge(:supervisor, name: name, root: @root, &block)
|
88
|
+
)
|
185
89
|
end
|
186
90
|
|
187
91
|
private
|
188
92
|
|
189
93
|
# Build a new environment with the specified name and the given parents.
|
190
94
|
# @parameter name [String]
|
191
|
-
# @parameter parents [Array(
|
95
|
+
# @parameter parents [Array(Symbol)]
|
192
96
|
# @yields {...} The block that will generate the environment.
|
193
|
-
def merge(
|
194
|
-
|
195
|
-
|
196
|
-
parent = Build::Environment.combine(*environments)
|
97
|
+
def merge(*parents, **initial, &block)
|
98
|
+
facets = parents.map{|parent| Environment::LEGACY_ENVIRONMENTS.fetch(parent)}
|
197
99
|
|
198
|
-
|
100
|
+
::Async::Service::Environment.build(*facets, **initial, &block)
|
199
101
|
end
|
200
102
|
end
|
201
103
|
end
|