ratalada 2.2.0 → 3.1.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/README.md +5 -0
- data/lib/ratalada/async.rb +35 -0
- data/lib/ratalada/builder.rb +1 -1
- data/lib/ratalada/falcon.rb +1 -1
- data/lib/ratalada/puma.rb +1 -1
- data/lib/ratalada/version.rb +1 -1
- data/lib/ratalada/webrick.rb +28 -0
- data/lib/ratalada.rb +9 -8
- metadata +17 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: '079378d0ea4867145471fa730a8d2eb6ec20513d50e7bfcb52b643cd99bbf6e2'
|
|
4
|
+
data.tar.gz: 228276a9a88b32c152a4e84eb12f267f62b8cde567d7d9dab9fae4734e207ab9
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5fa8af50cdf2da52fcc5e35d4a8f9acdd97307a6b1c5a7afd09d2971889331ec7af9f16a9472991db768fc71bb195174bf7c77e45fec50dded0b7696eef37c03
|
|
7
|
+
data.tar.gz: 939a4d0b6d7f9b1434561607ba7d02e44ab93a471abb8d7565e223a2b103434177648d648901fa65a75b001ced4a926aef14f95478cffeb1c1c1c885dbcfbb84
|
data/README.md
CHANGED
|
@@ -253,6 +253,11 @@ gem kit changelog --write --gem ratalada-roda
|
|
|
253
253
|
gem kit release --gem ratalada-roda # gate, build, push, tag
|
|
254
254
|
```
|
|
255
255
|
|
|
256
|
+
## Why
|
|
257
|
+
|
|
258
|
+
Spurred on by things like [this post](https://blainsmith.com/articles/just-fucking-use-go/), and just how easy it is to create servers with [hono](https://hono.dev/) or agents with [volt](https://github.com/voltagent/voltagent), which makes me irrationally angry that ruby hasn't more libraries like this considering it's WELL beyond javascript in it's flexibility as a language.
|
|
259
|
+
[This post is great](https://www.toptal.com/developers/ruby/api-with-sinatra-and-sequel-ruby-tutorial), but it shuold be even simpler.
|
|
260
|
+
|
|
256
261
|
## License
|
|
257
262
|
|
|
258
263
|
[MIT](LICENSE)
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "async/http/server"
|
|
4
|
+
require "async/http/endpoint"
|
|
5
|
+
require "protocol/rack/adapter"
|
|
6
|
+
require_relative "../ratalada"
|
|
7
|
+
|
|
8
|
+
module Ratalada
|
|
9
|
+
module Backends
|
|
10
|
+
# Falcon without falcon: one Async::HTTP::Server in this process, no
|
|
11
|
+
# container, no supervision, no restarts. Use ratalada/falcon when you
|
|
12
|
+
# want those; this is the fiber-based server on its own.
|
|
13
|
+
module Async
|
|
14
|
+
module_function
|
|
15
|
+
|
|
16
|
+
def run(app, host:, port:, count: 1)
|
|
17
|
+
if count > 1
|
|
18
|
+
warn "ratalada: async backend ignores count: (single process — use ratalada/falcon)"
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
endpoint = ::Async::HTTP::Endpoint.parse("http://#{host}:#{port}")
|
|
22
|
+
server = ::Async::HTTP::Server.new(::Protocol::Rack::Adapter.new(app), endpoint)
|
|
23
|
+
|
|
24
|
+
warn "ratalada: async listening on http://#{host}:#{port}"
|
|
25
|
+
# #run wraps itself in Async{}, which outside a reactor starts one and
|
|
26
|
+
# blocks until the accept loop ends.
|
|
27
|
+
server.run
|
|
28
|
+
rescue Interrupt
|
|
29
|
+
# clean shutdown
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
config.backend = Backends::Async
|
|
35
|
+
end
|
data/lib/ratalada/builder.rb
CHANGED
data/lib/ratalada/falcon.rb
CHANGED
data/lib/ratalada/puma.rb
CHANGED
data/lib/ratalada/version.rb
CHANGED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "rackup/handler/webrick"
|
|
4
|
+
require_relative "../ratalada"
|
|
5
|
+
|
|
6
|
+
module Ratalada
|
|
7
|
+
module Backends
|
|
8
|
+
# Stdlib WEBrick via rackup's handler, which already does the rack env
|
|
9
|
+
# translation. Single process, one thread per connection — fine for
|
|
10
|
+
# development and tests, not what you ship.
|
|
11
|
+
module Webrick
|
|
12
|
+
module_function
|
|
13
|
+
|
|
14
|
+
def run(app, host:, port:, count: 1)
|
|
15
|
+
if count > 1
|
|
16
|
+
warn "ratalada: webrick backend ignores count: (single process)"
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
warn "ratalada: webrick listening on http://#{host}:#{port}"
|
|
20
|
+
::Rackup::Handler::WEBrick.run(app, Host: host, Port: port)
|
|
21
|
+
rescue Interrupt
|
|
22
|
+
::Rackup::Handler::WEBrick.shutdown
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
config.backend = Backends::Webrick
|
|
28
|
+
end
|
data/lib/ratalada.rb
CHANGED
|
@@ -18,8 +18,10 @@ module Ratalada
|
|
|
18
18
|
super(msg || <<~MSG)
|
|
19
19
|
No server backend selected. Require one before calling Server.run:
|
|
20
20
|
|
|
21
|
-
require "ratalada/puma"
|
|
22
|
-
require "ratalada/falcon"
|
|
21
|
+
require "ratalada/puma" # or
|
|
22
|
+
require "ratalada/falcon" # or
|
|
23
|
+
require "ratalada/async" # or
|
|
24
|
+
require "ratalada/webrick"
|
|
23
25
|
MSG
|
|
24
26
|
end
|
|
25
27
|
end
|
|
@@ -28,15 +30,12 @@ module Ratalada
|
|
|
28
30
|
# The backend runs a rack app (set by requiring ratalada/puma or
|
|
29
31
|
# ratalada/falcon); the frontend turns the Server.run block into a rack
|
|
30
32
|
# app (the built-in router by default, ratalada/sinatra to swap it).
|
|
31
|
-
|
|
32
|
-
|
|
33
|
+
# Both are settings, so `Server.run(frontend: ...)` writes them too.
|
|
33
34
|
def backend
|
|
34
|
-
|
|
35
|
+
config.backend or raise NoBackendError
|
|
35
36
|
end
|
|
36
37
|
|
|
37
|
-
def frontend
|
|
38
|
-
@frontend ||= Frontends::Routes
|
|
39
|
-
end
|
|
38
|
+
def frontend = config.frontend
|
|
40
39
|
end
|
|
41
40
|
|
|
42
41
|
# Rack::Request plus just enough sugar to pattern match on, so everything
|
|
@@ -196,6 +195,8 @@ end
|
|
|
196
195
|
|
|
197
196
|
# Core settings. Contrib gems (ratalada-contrib et al.) register theirs the
|
|
198
197
|
# same way — Ratalada.setting at the bottom of their own file.
|
|
198
|
+
Ratalada.setting :backend
|
|
199
|
+
Ratalada.setting :frontend, default: Ratalada::Frontends::Routes
|
|
199
200
|
Ratalada.setting :host, default: Ratalada::DEFAULT_HOST
|
|
200
201
|
Ratalada.setting :port, default: Ratalada::DEFAULT_PORT, constructor: ->(value) { Integer(value) }
|
|
201
202
|
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.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Nathan K
|
|
@@ -107,6 +107,20 @@ dependencies:
|
|
|
107
107
|
- - ">="
|
|
108
108
|
- !ruby/object:Gem::Version
|
|
109
109
|
version: '0'
|
|
110
|
+
- !ruby/object:Gem::Dependency
|
|
111
|
+
name: webrick
|
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
|
113
|
+
requirements:
|
|
114
|
+
- - ">="
|
|
115
|
+
- !ruby/object:Gem::Version
|
|
116
|
+
version: '0'
|
|
117
|
+
type: :development
|
|
118
|
+
prerelease: false
|
|
119
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
120
|
+
requirements:
|
|
121
|
+
- - ">="
|
|
122
|
+
- !ruby/object:Gem::Version
|
|
123
|
+
version: '0'
|
|
110
124
|
- !ruby/object:Gem::Dependency
|
|
111
125
|
name: lefthook
|
|
112
126
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -135,10 +149,12 @@ files:
|
|
|
135
149
|
- README.md
|
|
136
150
|
- exe/ratalada
|
|
137
151
|
- lib/ratalada.rb
|
|
152
|
+
- lib/ratalada/async.rb
|
|
138
153
|
- lib/ratalada/builder.rb
|
|
139
154
|
- lib/ratalada/falcon.rb
|
|
140
155
|
- lib/ratalada/puma.rb
|
|
141
156
|
- lib/ratalada/version.rb
|
|
157
|
+
- lib/ratalada/webrick.rb
|
|
142
158
|
homepage: https://github.com/n-at-han-k/ratalada
|
|
143
159
|
licenses:
|
|
144
160
|
- MIT
|