sinatra-homura 0.3.1 → 0.3.2
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/CHANGELOG.md +10 -0
- data/lib/sinatra/homura.rb +2 -0
- data/lib/sinatra/scheduled.rb +16 -20
- data/templates/Rakefile.example +1 -1
- metadata +11 -5
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 0772bd5644111e46f314060d774ac9b745e3aa7b729ee4616a4e90081014fe1b
|
|
4
|
+
data.tar.gz: 69aef71d42ca1cb508489b54ccb733325eb6f22cdd5bfce85c447922b525eefd
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 98e9aac3947b40385d6c8ff2ccfd3a0dfc9f42b70b1b1a9d078fed41ed3e3a3e6f7e2e13c9241e0abd81f77d8fcf188a139e513188c3939114d6046377f176d5
|
|
7
|
+
data.tar.gz: 6134f4fb4d2b7483c3cb840693a3ab3471d843bbb96223a2c4ce7e3cefcd2c577d611c32c86870dd82ff646a36d12202fecbc5588ad5a68fb6264bebfadffbb3
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.3.2 (2026-05-03)
|
|
4
|
+
|
|
5
|
+
- Register `Cloudflare::BindingHelpers` on `Sinatra::Base`, making D1,
|
|
6
|
+
KV, R2, Workers AI, Email, Queues, Cache, and Durable Object bindings
|
|
7
|
+
available through Ruby-shaped helpers in normal routes.
|
|
8
|
+
- Route scheduled jobs through the same binding env builder as HTTP,
|
|
9
|
+
then expose the same helpers on `ScheduledContext`.
|
|
10
|
+
- Require `homura-runtime >= 0.3.5` so the helper surface and shared
|
|
11
|
+
binding builder are present.
|
|
12
|
+
|
|
3
13
|
## 0.3.1 (2026-04-30)
|
|
4
14
|
|
|
5
15
|
- README: drop the leftover `require 'sinatra/cloudflare_workers'` snippet
|
data/lib/sinatra/homura.rb
CHANGED
|
@@ -83,6 +83,8 @@ module Sinatra
|
|
|
83
83
|
end
|
|
84
84
|
end
|
|
85
85
|
|
|
86
|
+
Sinatra::Base.helpers Cloudflare::BindingHelpers if defined?(Sinatra::Base) && defined?(Cloudflare::BindingHelpers)
|
|
87
|
+
|
|
86
88
|
# Kept for backward compatibility with code that still wires up at_exit
|
|
87
89
|
# explicitly; harmless on Workers because the isolate doesn't exit.
|
|
88
90
|
at_exit { Sinatra::Homura.ensure_rack_app! }
|
data/lib/sinatra/scheduled.rb
CHANGED
|
@@ -14,11 +14,10 @@
|
|
|
14
14
|
# register Sinatra::Scheduled
|
|
15
15
|
#
|
|
16
16
|
# schedule '*/5 * * * *', name: 'heartbeat' do |event|
|
|
17
|
-
# db = env['cloudflare.DB']
|
|
18
17
|
# db.execute_insert(
|
|
19
18
|
# 'INSERT INTO heartbeats (cron, scheduled_at) VALUES (?, ?)',
|
|
20
19
|
# [event.cron, event.scheduled_time.to_i]
|
|
21
|
-
# )
|
|
20
|
+
# )
|
|
22
21
|
# end
|
|
23
22
|
#
|
|
24
23
|
# schedule '0 */1 * * *' do |event|
|
|
@@ -216,9 +215,8 @@ module Sinatra
|
|
|
216
215
|
|
|
217
216
|
private
|
|
218
217
|
|
|
219
|
-
# Build a tiny Rack-shaped env so the block has the same
|
|
220
|
-
#
|
|
221
|
-
# routes use. We deliberately do NOT spin up a full Sinatra
|
|
218
|
+
# Build a tiny Rack-shaped env so the block has the same binding
|
|
219
|
+
# helpers that HTTP routes use. We deliberately do NOT spin up a full Sinatra
|
|
222
220
|
# request — there is no HTTP request, no params, no response.
|
|
223
221
|
def invoke_scheduled_job(job, event, js_env, js_ctx)
|
|
224
222
|
env = build_scheduled_env(event, js_env, js_ctx)
|
|
@@ -264,23 +262,12 @@ module Sinatra
|
|
|
264
262
|
end
|
|
265
263
|
|
|
266
264
|
def build_scheduled_env(event, js_env, js_ctx)
|
|
267
|
-
|
|
265
|
+
Cloudflare::Bindings.build_env(js_env, js_ctx, {
|
|
268
266
|
'cloudflare.scheduled' => true,
|
|
269
267
|
'cloudflare.event' => event,
|
|
270
268
|
'cloudflare.cron' => event.cron,
|
|
271
|
-
'cloudflare.scheduled_time' => event.scheduled_time
|
|
272
|
-
|
|
273
|
-
'cloudflare.ctx' => js_ctx
|
|
274
|
-
}
|
|
275
|
-
if js_env
|
|
276
|
-
js_db = `#{js_env} && #{js_env}.DB`
|
|
277
|
-
js_kv = `#{js_env} && #{js_env}.KV`
|
|
278
|
-
js_r2 = `#{js_env} && #{js_env}.BUCKET`
|
|
279
|
-
env['cloudflare.DB'] = ::Cloudflare::D1Database.new(js_db) if `#{js_db} != null`
|
|
280
|
-
env['cloudflare.KV'] = ::Cloudflare::KVNamespace.new(js_kv) if `#{js_kv} != null`
|
|
281
|
-
env['cloudflare.BUCKET'] = ::Cloudflare::R2Bucket.new(js_r2) if `#{js_r2} != null`
|
|
282
|
-
end
|
|
283
|
-
env
|
|
269
|
+
'cloudflare.scheduled_time' => event.scheduled_time
|
|
270
|
+
})
|
|
284
271
|
end
|
|
285
272
|
end
|
|
286
273
|
|
|
@@ -298,9 +285,18 @@ module Sinatra
|
|
|
298
285
|
@js_ctx = js_ctx
|
|
299
286
|
end
|
|
300
287
|
|
|
301
|
-
def
|
|
288
|
+
def d1; env['cloudflare.DB']; end
|
|
289
|
+
def db; d1; end
|
|
290
|
+
def cf_env; env['cloudflare.env']; end
|
|
291
|
+
def cf_ctx; env['cloudflare.ctx']; end
|
|
302
292
|
def kv; env['cloudflare.KV']; end
|
|
303
293
|
def bucket; env['cloudflare.BUCKET']; end
|
|
294
|
+
def ai; Cloudflare::Bindings.ai(env); end
|
|
295
|
+
def send_email; env['cloudflare.SEND_EMAIL']; end
|
|
296
|
+
def jobs_queue; env['cloudflare.QUEUE_JOBS']; end
|
|
297
|
+
def durable_object(name, id_or_name = nil)
|
|
298
|
+
Cloudflare::Bindings.durable_object(env, name, id_or_name)
|
|
299
|
+
end
|
|
304
300
|
|
|
305
301
|
# Forward a long-running promise to the Workers runtime so the
|
|
306
302
|
# job can return immediately while the work continues.
|
data/templates/Rakefile.example
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
#
|
|
3
3
|
# Example Rake tasks for a Sinatra-on-Cloudflare-Workers project using
|
|
4
|
-
# sinatra-
|
|
4
|
+
# sinatra-homura + homura-runtime.
|
|
5
5
|
#
|
|
6
6
|
# Copy to your app root as `Rakefile` and adjust paths.
|
|
7
7
|
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: sinatra-homura
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.3.
|
|
4
|
+
version: 0.3.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Kazuhiro Homma
|
|
@@ -13,16 +13,22 @@ dependencies:
|
|
|
13
13
|
name: homura-runtime
|
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|
|
15
15
|
requirements:
|
|
16
|
-
- - "
|
|
16
|
+
- - ">="
|
|
17
17
|
- !ruby/object:Gem::Version
|
|
18
|
-
version:
|
|
18
|
+
version: 0.3.5
|
|
19
|
+
- - "<"
|
|
20
|
+
- !ruby/object:Gem::Version
|
|
21
|
+
version: '0.4'
|
|
19
22
|
type: :runtime
|
|
20
23
|
prerelease: false
|
|
21
24
|
version_requirements: !ruby/object:Gem::Requirement
|
|
22
25
|
requirements:
|
|
23
|
-
- - "
|
|
26
|
+
- - ">="
|
|
27
|
+
- !ruby/object:Gem::Version
|
|
28
|
+
version: 0.3.5
|
|
29
|
+
- - "<"
|
|
24
30
|
- !ruby/object:Gem::Version
|
|
25
|
-
version: '0.
|
|
31
|
+
version: '0.4'
|
|
26
32
|
- !ruby/object:Gem::Dependency
|
|
27
33
|
name: opal-homura
|
|
28
34
|
requirement: !ruby/object:Gem::Requirement
|