ratalada 2.1.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/ratalada/builder.rb +1 -1
- data/lib/ratalada/falcon.rb +12 -6
- data/lib/ratalada/puma.rb +4 -2
- data/lib/ratalada/version.rb +1 -1
- data/lib/ratalada.rb +47 -16
- metadata +18 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8d0e58c60b99a4b05777a6089c484f2104f85924694cfe0b5c0ef543a03634c7
|
|
4
|
+
data.tar.gz: d04a10b62a3f33a00489234bbb0db780517a54c7569c83dfd098cee69a3b2f5f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 616cb51549da081369ce6df606e8c9188900b20fc7dc5344b045eaf8ab0618edc8f1cba92fd21be24c59cae0370b2fdfe6729e56e1bf93562b118ebd2f75f4e4
|
|
7
|
+
data.tar.gz: f834abb138626a902d8c4947183bca135d0ddf6ab9c8ed92a68b6ba08cc45666edb5f9f55611b50f365e4adbb23c20d621c8fdab2a532a1721c0d0e06e0642e3
|
data/lib/ratalada/builder.rb
CHANGED
data/lib/ratalada/falcon.rb
CHANGED
|
@@ -27,20 +27,26 @@ module Ratalada
|
|
|
27
27
|
middleware = ::Falcon::Server.rack_middleware(app, cache: cache)
|
|
28
28
|
|
|
29
29
|
environment = Async::Service::Environment.new(::Falcon::Environment::Server).with(
|
|
30
|
-
name:
|
|
31
|
-
url:
|
|
32
|
-
middleware:
|
|
30
|
+
name: "ratalada",
|
|
31
|
+
url: "http://#{host}:#{port}",
|
|
32
|
+
middleware: -> { middleware },
|
|
33
33
|
container_options: { count: count, restart: true },
|
|
34
34
|
# async-service >= 0.25 reads `root` in Managed::Service#preload!
|
|
35
35
|
# unconditionally (the default `preload` is `[]`, which is truthy),
|
|
36
36
|
# so an environment without one raises NoMethodError on boot.
|
|
37
|
-
root:
|
|
37
|
+
root: Dir.pwd,
|
|
38
38
|
)
|
|
39
39
|
|
|
40
40
|
configuration = Async::Service::Configuration.new
|
|
41
41
|
configuration.add(environment)
|
|
42
42
|
|
|
43
|
-
|
|
43
|
+
if count > 1
|
|
44
|
+
workers = " (#{count} workers)"
|
|
45
|
+
else
|
|
46
|
+
workers = ""
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
warn "ratalada: falcon listening on http://#{host}:#{port}#{workers}"
|
|
44
50
|
Async::Service::Controller.run(configuration, container_class: Async::Container.best_container_class)
|
|
45
51
|
rescue Interrupt
|
|
46
52
|
# clean shutdown
|
|
@@ -48,5 +54,5 @@ module Ratalada
|
|
|
48
54
|
end
|
|
49
55
|
end
|
|
50
56
|
|
|
51
|
-
|
|
57
|
+
config.backend = Backends::Falcon
|
|
52
58
|
end
|
data/lib/ratalada/puma.rb
CHANGED
|
@@ -9,7 +9,9 @@ module Ratalada
|
|
|
9
9
|
module_function
|
|
10
10
|
|
|
11
11
|
def run(app, host:, port:, count: 1)
|
|
12
|
-
|
|
12
|
+
if count > 1
|
|
13
|
+
warn "ratalada: puma backend ignores count: (not yet implemented)"
|
|
14
|
+
end
|
|
13
15
|
server = ::Puma::Server.new(app)
|
|
14
16
|
server.add_tcp_listener(host, port)
|
|
15
17
|
warn "ratalada: puma listening on http://#{host}:#{port}"
|
|
@@ -20,5 +22,5 @@ module Ratalada
|
|
|
20
22
|
end
|
|
21
23
|
end
|
|
22
24
|
|
|
23
|
-
|
|
25
|
+
config.backend = Backends::Puma
|
|
24
26
|
end
|
data/lib/ratalada/version.rb
CHANGED
data/lib/ratalada.rb
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require "rack"
|
|
4
|
+
require "dry-configurable"
|
|
4
5
|
require_relative "ratalada/version"
|
|
5
6
|
|
|
6
7
|
module Ratalada
|
|
@@ -8,6 +9,8 @@ module Ratalada
|
|
|
8
9
|
DEFAULT_PORT = Integer(ENV.fetch("PORT", "9292"))
|
|
9
10
|
DEFAULT_COUNT = Integer(ENV.fetch("COUNT", "1"))
|
|
10
11
|
|
|
12
|
+
extend Dry::Configurable
|
|
13
|
+
|
|
11
14
|
class Error < StandardError; end
|
|
12
15
|
|
|
13
16
|
class NoBackendError < Error
|
|
@@ -25,15 +28,12 @@ module Ratalada
|
|
|
25
28
|
# The backend runs a rack app (set by requiring ratalada/puma or
|
|
26
29
|
# ratalada/falcon); the frontend turns the Server.run block into a rack
|
|
27
30
|
# app (the built-in router by default, ratalada/sinatra to swap it).
|
|
28
|
-
|
|
29
|
-
|
|
31
|
+
# Both are settings, so `Server.run(frontend: ...)` writes them too.
|
|
30
32
|
def backend
|
|
31
|
-
|
|
33
|
+
config.backend or raise NoBackendError
|
|
32
34
|
end
|
|
33
35
|
|
|
34
|
-
def frontend
|
|
35
|
-
@frontend ||= Frontends::Routes
|
|
36
|
-
end
|
|
36
|
+
def frontend = config.frontend
|
|
37
37
|
end
|
|
38
38
|
|
|
39
39
|
# Rack::Request plus just enough sugar to pattern match on, so everything
|
|
@@ -91,10 +91,10 @@ module Ratalada
|
|
|
91
91
|
|
|
92
92
|
def call(env)
|
|
93
93
|
request = Request.new(env)
|
|
94
|
-
|
|
95
|
-
@router.call(request)
|
|
94
|
+
begin
|
|
95
|
+
handler = @router.call(request)
|
|
96
96
|
rescue NoMatchingPatternError
|
|
97
|
-
nil
|
|
97
|
+
handler = nil
|
|
98
98
|
end
|
|
99
99
|
respond(handler, request)
|
|
100
100
|
end
|
|
@@ -133,8 +133,11 @@ module Ratalada
|
|
|
133
133
|
# count runs that many worker processes accepting from a shared socket,
|
|
134
134
|
# like node's cluster module. Each worker has its own state — anything
|
|
135
135
|
# shared (sessions, caches) needs an external store or count: 1.
|
|
136
|
-
|
|
137
|
-
|
|
136
|
+
#
|
|
137
|
+
# host:, port: and count: are written through to Ratalada.config before
|
|
138
|
+
# boot, so Server.run(port: 3000) is shorthand for configuring first.
|
|
139
|
+
def run(**options, &block)
|
|
140
|
+
Stack.new.run(**options, &block)
|
|
138
141
|
end
|
|
139
142
|
|
|
140
143
|
# The chain Server.use returns. Collects middleware until run ends it.
|
|
@@ -148,11 +151,29 @@ module Ratalada
|
|
|
148
151
|
self
|
|
149
152
|
end
|
|
150
153
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
+
# Every option is a Ratalada.config setting name (host, port, count);
|
|
155
|
+
# each is applied to the config verbatim — coercion and rejection of
|
|
156
|
+
# unknown names are the settings' own. Skipped entirely when no
|
|
157
|
+
# options are given so a finalized config can still boot.
|
|
158
|
+
def run(**options, &block)
|
|
159
|
+
unless block
|
|
160
|
+
raise ArgumentError, "Server.run requires a block"
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
if options.any?
|
|
164
|
+
Ratalada.configure do |config|
|
|
165
|
+
options.each do |key, value|
|
|
166
|
+
config[key] = value
|
|
167
|
+
end
|
|
168
|
+
end
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
config = Ratalada.config
|
|
172
|
+
unless config.count.is_a?(Integer) && config.count.positive?
|
|
173
|
+
raise ArgumentError, "count must be a positive Integer"
|
|
174
|
+
end
|
|
154
175
|
|
|
155
|
-
Ratalada.backend.run(to_app(block), host: host, port: port, count: count)
|
|
176
|
+
Ratalada.backend.run(to_app(block), host: config.host, port: config.port, count: config.count)
|
|
156
177
|
end
|
|
157
178
|
|
|
158
179
|
# First `use` in the chain is the outermost, as in Rack::Builder.
|
|
@@ -166,4 +187,14 @@ module Ratalada
|
|
|
166
187
|
end
|
|
167
188
|
|
|
168
189
|
# The whole point is a zero-ceremony top-level DSL.
|
|
169
|
-
|
|
190
|
+
unless defined?(Server)
|
|
191
|
+
Server = Ratalada::Server
|
|
192
|
+
end
|
|
193
|
+
|
|
194
|
+
# Core settings. Contrib gems (ratalada-contrib et al.) register theirs the
|
|
195
|
+
# same way — Ratalada.setting at the bottom of their own file.
|
|
196
|
+
Ratalada.setting :backend
|
|
197
|
+
Ratalada.setting :frontend, default: Ratalada::Frontends::Routes
|
|
198
|
+
Ratalada.setting :host, default: Ratalada::DEFAULT_HOST
|
|
199
|
+
Ratalada.setting :port, default: Ratalada::DEFAULT_PORT, constructor: ->(value) { Integer(value) }
|
|
200
|
+
Ratalada.setting :count, default: Ratalada::DEFAULT_COUNT, constructor: ->(value) { Integer(value) }
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ratalada
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 3.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Nathan K
|
|
@@ -24,19 +24,33 @@ dependencies:
|
|
|
24
24
|
- !ruby/object:Gem::Version
|
|
25
25
|
version: '3.0'
|
|
26
26
|
- !ruby/object:Gem::Dependency
|
|
27
|
-
name:
|
|
27
|
+
name: dry-configurable
|
|
28
28
|
requirement: !ruby/object:Gem::Requirement
|
|
29
29
|
requirements:
|
|
30
30
|
- - "~>"
|
|
31
31
|
- !ruby/object:Gem::Version
|
|
32
|
-
version: '
|
|
32
|
+
version: '1.4'
|
|
33
|
+
type: :runtime
|
|
34
|
+
prerelease: false
|
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - "~>"
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: '1.4'
|
|
40
|
+
- !ruby/object:Gem::Dependency
|
|
41
|
+
name: rspec
|
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
|
43
|
+
requirements:
|
|
44
|
+
- - "~>"
|
|
45
|
+
- !ruby/object:Gem::Version
|
|
46
|
+
version: '3.13'
|
|
33
47
|
type: :development
|
|
34
48
|
prerelease: false
|
|
35
49
|
version_requirements: !ruby/object:Gem::Requirement
|
|
36
50
|
requirements:
|
|
37
51
|
- - "~>"
|
|
38
52
|
- !ruby/object:Gem::Version
|
|
39
|
-
version: '
|
|
53
|
+
version: '3.13'
|
|
40
54
|
- !ruby/object:Gem::Dependency
|
|
41
55
|
name: rake
|
|
42
56
|
requirement: !ruby/object:Gem::Requirement
|