Skip to content

GemStack 0.4.0

Choose a tag to compare

@github-actions github-actions released this 06 Oct 11:44
· 22 commits to main since this release

Upgrading from 0.3.x: run gemstack update (it also updates the files gemstack new wrote). Apps that
added realtime: copy frontend/lib/gemstack/realtime.ts from a fresh gemstack add realtime for
WebSockets, realtime.send, presence and the offline status — the old client keeps working over
Server-Sent Events. Validation error messages now list the failures (the errors hash is unchanged).

  • Model enums: enum :status, %w[draft published archived], default: "draft" — a string column
    limited to those values, validated, accepted only with those values by the request schema, typed
    "draft" | "published" | "archived" in TypeScript and OpenAPI, with Product.statuses, draft?,
    published! and chainable Product.published (prefix: for clashes). Generators take
    status:enum:draft,published,archived (migration column, the enum line, a <select> in the form).
    Schemas and fields take enum: too.
  • Validation errors say what failed in their message — "Validation failed: price must be greater than 0" —
    not only in errors, and generated forms show the message when an error belongs to no field in the form
    (e.g. errors.add(:base, …)); before, such errors left the form without any message.
  • Realtime runs over WebSockets. gemstack add realtime gives one WebSocket per browser tab on
    /api/realtime (same origin; the dev gateway and kamal-proxy route it with /api), carrying
    subscriptions, broadcasts, browser → server messages (realtime.send → receive in
    config/channels.rb, with replies), presence (channel "rooms:*", presence: true, usePresence,
    GemStack::Realtime.present_on), connection identity (identify) and replay after reconnects. The
    browser client reconnects with backoff, resubscribes and de-duplicates; Origins are checked and
    messages are size- and rate-limited. GemStack.broadcast, channel rules and brokers are unchanged.
  • Server-Sent Events are a full second transport with the same features (receive via POST,
    presence, identity, replay). config.realtime.transports (default [:websocket, :sse]) says what the
    server accepts; NEXT_PUBLIC_GEMSTACK_REALTIME (auto — the default: WebSocket, falling back to SSE when
    one can't be opened — websocket or sse) what the browser uses. App code is the same either way.
    useRealtimeStatus() adds offline (the browser lost its network), realtime.transport says which one
    is in use, and presence survives a reconnect within config.realtime.presence_grace (3 s). Apps on the
    old realtime.ts keep working; copy the new client to get the rest (docs/realtime.md).
  • GemStack::Auth.user_from(request): the signed-in user outside controllers (session cookie or API
    token), e.g. for realtime's identify.
  • Background jobs work from gemstack new: apps with a database get the jobs table, gemstack new
    migrates, and gemstack dev runs a worker from the first run. Jobs still run only via perform_later.
  • New apps include gem "brotli", so responses are Brotli-compressed for browsers that accept it
    (gzip otherwise; compression was already on by default).
  • PostgreSQL is the recommended production database: config/database.yml, the Kamal config and
    gemstack doctor --production say how to use it (DATABASE_URL). SQLite stays the development default.
  • GemStack now describes itself as "a fast, modular Ruby web application framework with a Next.js frontend"
    (README, gem READMEs and the gem summary on rubygems.org).