Skip to content

About

Rails integration for Cabby, the real-time server: Action Cable connections and channels over HTTP RPC, in pure Ruby

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

cabby-rails

The Rails integration for Cabby, the real-time server. Cabby holds the WebSocket connections; your app keeps its own ApplicationCable::Connection and channels, and Cabby calls it over HTTP to run them. Pure Ruby, no native extensions.

Requirements: Ruby 3.2+, Rails 8.0 or 8.1, a cabby server.

Install

# Gemfile
gem "cabby-rails"
bundle install
bin/rails g cabby:setup

The generator writes config/cabby.yml, sets adapter: cabby in config/cable.yml for development and production (test is left alone; the settings of the adapter it replaces, such as a Redis url, are commented out there), mounts the endpoint in config/routes.rb, sets up the server for development (see Run Cabby) and prints what is left to do. Running it again changes nothing. bin/rails g cabby:client then sets up the browser client, for Turbo Streams too (below).

# config/routes.rb (what the generator adds)
mount Cabby::Rails::RPC => "/_cabby"

How it works

  1. Browsers connect to Cabby (ws://localhost:8080/cable) with the usual Action Cable client.
  2. Cabby calls POST /_cabby/connect, /command and /disconnect on the app.
  3. Each call builds your real connection and channel, runs your code, and answers with the identifiers, streams and messages; Cabby keeps the subscriptions.
  4. Broadcasts from the app (ActionCable.server.broadcast, broadcast_to, Turbo) go to Cabby through adapter: cabby.
  5. App and server share one secret: it authenticates the calls both ways.

Run Cabby

In development, cabby:setup sets the server up the way the app runs:

--development Writes Start with
bin a cabby: line in Procfile.dev, bin/cabby bin/dev; foreman start -f Procfile.dev when bin/dev does not run Procfile.dev (the generator says which)
puma plugin :cabby in config/puma.rb, bin/cabby CABBY_IN_PUMA=1 bin/rails server
docker nothing: prints a Docker Compose snippet (ghcr.io/danig2k/cabby:0.6.0) docker compose up
skip nothing: prints the command cabby ...

Without the option it takes bin when the app has a Procfile.dev, else puma when it has a config/puma.rb, else skip; it asks only on a terminal. The command it writes:

bin/cabby --rpc_host=http://localhost:3000/_cabby --secret=$CABBY_SECRET --broadcast_adapter=http --turbo_streams --turbo_streams_secret=$CABBY_TURBO_STREAMS_SECRET --port=8080

--turbo_streams and --turbo_streams_secret come with Turbo (below); --port=8080 because bin/dev gives each process a PORT, which the server reads.

bin/cabby runs the server with every argument it gets. Its first run downloads the server release this gem was tested with (0.6.0) into bin/dist/ (git-ignored), checked against the release's SHA256SUMS; later runs start offline. To pin another version, edit the line in bin/cabby: "0.6.0", or "0.6" for the latest 0.6.x. A full version is downloaded from the release's files on GitHub, with no API call and so no rate limit; "0.6" lists the repository's tags with git ls-remote. CABBY_RELEASES_URL replaces the repository address with a mirror that serves the same releases/download/v<version>/<file> paths. Prebuilt servers exist for Linux (x86_64, arm64, glibc) and macOS on Apple silicon; elsewhere, install the server another way and run cabby.

plugin :cabby starts the server once Puma has booted and stops it once Puma has stopped (Puma 6 or later). Ctrl-C reaches Puma only; the server keeps running across bin/rails restart; a server left by a killed Puma is stopped at the next start. Settings, after the plugin line:

cabby_command "bin/cabby --port=8080 ..."   # run by the shell, as in Procfile.dev (default: bin/cabby)
cabby_log "log/cabby.log"                   # default: Puma's output
cabby_pidfile "tmp/pids/cabby.pid"          # the default

By hand, or in production:

export CABBY_SECRET=$(bin/rails secret)        # or the credentials, see config/cabby.yml
cabby --rpc_host=http://localhost:3000/_cabby --secret=$CABBY_SECRET

With Turbo, add --turbo_streams --turbo_streams_secret=$CABBY_TURBO_STREAMS_SECRET (see below). Cabby forwards the Cookie header to connect; list any other header it reads: --headers=cookie,x-tenant.

Without a secret the endpoint answers only in development and test; outside development and test it refuses every call (and says so in the log).

Configuration

config/cabby.yml (per environment, ERB, a default block with an alias works), then CABBY_* variables, then Cabby.configure { |c| ... } in an initializer, each over the one before. A key the gem does not know in config/cabby.yml is an error. Where the server reads the same variable, so does the gem, with the server's default.

Setting Variable Default
secret CABBY_SECRET none
http_rpc_secret CABBY_HTTP_RPC_SECRET derived from secret
url CABBY_URL none (browsers' WebSocket URL; given to Action Cable when the app sets none)
broadcast_adapter CABBY_BROADCAST_ADAPTER http
broadcast_url CABBY_BROADCAST_URL http://localhost:8080/_broadcast with a secret or key, else http://localhost:8090/_broadcast
broadcast_key CABBY_BROADCAST_KEY derived from secret
broadcast_open_timeout CABBY_BROADCAST_OPEN_TIMEOUT 2 (seconds)
broadcast_read_timeout CABBY_BROADCAST_READ_TIMEOUT 5 (seconds)
postgres_schema CABBY_POSTGRES_SCHEMA public
postgres_table_prefix CABBY_POSTGRES_TABLE_PREFIX cabby_
redis_url CABBY_REDIS_URL, REDIS_URL redis://localhost:6379
redisx_stream CABBY_REDISX_STREAM the server's
redis_channel CABBY_REDIS_CHANNEL the server's
nats_servers CABBY_NATS_SERVERS nats://127.0.0.1:4222
nats_channel CABBY_NATS_CHANNEL the server's
streams_secret CABBY_STREAMS_SECRET secret
turbo_streams_secret CABBY_TURBO_STREAMS_SECRET streams_secret, then secret
turbo_streams CABBY_TURBO_STREAMS true (give Turbo the server's key)
turbo_streams_since CABBY_TURBO_STREAMS_SINCE false (turbo_stream_from renders since, below)
jwt_secret CABBY_JWT_SECRET secret (the key tokens are signed with)
jwt_param CABBY_JWT_PARAM jid (the query parameter action_cable_with_jwt_meta_tag puts the token in)
jwt_ttl CABBY_JWT_TTL 3600 (seconds a token is valid)
rpc_max_body_size CABBY_RPC_MAX_BODY_SIZE 16 MiB

As on the server, secret: none counts as unset, and none for another secret or key turns it off with no fallback to secret: with turbo_streams_secret: none the gem gives Turbo no key, and Cabby (0.6 and later, with --turbo_streams) rejects every Turbo Streams name.

Broadcasting

With adapter: cabby, ActionCable.server.broadcast, broadcast_to, Turbo's broadcasts and ActionCable.server.remote_connections.where(...).disconnect reach Cabby. where takes every identifier the connection declares, nil included, as in Action Cable. From anywhere:

Cabby.broadcast("chat_#{room.id}", { text: "hi" })
Cabby.broadcast("chat_#{room.id}", { text: "hi" }, exclude_socket: Cabby::Rails.current_sid) # not the sender
Cabby.broadcast_batch([{ stream: "a", data: { n: 1 } }, { stream: "b", data: "two" }])

Cabby::Rails.current_sid is the session id of the client being served: the one of the RPC call being handled, or the X-Socket-ID header of an HTTP request (nil outside both).

broadcast_adapter Run Cabby with The app needs
http --broadcast_adapter=http (default) nothing
postgres --broadcast_adapter=postgres --postgres_url=... Active Record on PostgreSQL; a broadcast in a transaction is sent only if it commits
redisx --broadcast_adapter=redisx redis-client or redis
redis --broadcast_adapter=redis (live only, no history) redis-client or redis
nats --broadcast_adapter=nats nats-pure

A refused or failed broadcast raises Cabby::BroadcastError (#status holds the HTTP status).

To everyone but the sender

A browser sends its session id with its requests as X-Socket-ID (the client's sessionId, see the browser client). While the app handles that request, to_others: true skips that browser's connection:

ActionCable.server.broadcast("chat_#{room.id}", { text: "hi" }, to_others: true)
ChatChannel.broadcast_to(room, { text: "hi" }, to_others: true)
ChatChannel.broadcast_to(room, { text: "hi" }, exclude_socket: socket_id)    # a session id you hold

Cabby::Rails.broadcasting_to_others do                                       # broadcasts made by other code
  Turbo::StreamsChannel.broadcast_remove_to(room, target: message)
end

The header is read by a Rack middleware the gem adds to the app's stack, so every controller and Rack endpoint sees it, and it ends with the request. Inside an RPC call, the session id is the one Cabby sent. With no session id, to_others: true reaches everyone. The options are accepted with any adapter (the test adapter too); only adapter: cabby acts on them.

The id names one connection, the @cabby/web client's, and what is skipped is that client's own subscriptions. A Turbo broadcast made in a request leaves out the page that made it when that page runs its turbo_stream_from tags on the client (cabby:client). Without it, the tags subscribe through Turbo's own connection, which has no id to send, and the broadcast still reaches that page.

The exclusion applies when a broadcast is delivered. A client that reconnects and asks for the messages it missed gets them from the server's history, the one it was left out of included: give messages an id, so the page can tell one it already shows.

A job does not carry the session id: a broadcast made in a job (Turbo's broadcast_*_later_to, which broadcasts_to in models uses) reaches everyone. Pass the id to the job yourself and use exclude_socket: there:

NotifyRoomJob.perform_later(room, text, socket_id: Cabby::Rails.current_sid)
# in the job
ChatChannel.broadcast_to(room, { text: text }, exclude_socket: socket_id)

Signed streams

Cabby subscribes a client to a signed stream name on its own, with no call to the app:

Cabby.sign_stream("room-#{room.id}")    # needs streams_secret or secret
Cabby.verify_stream(signed)             # the name, or nil
<%= cabby_signed_stream_name("room-#{room.id}") %>

The client subscribes with { channel: "$pubsub", signed_stream_name: "..." }, and Cabby.broadcast("room-#{room.id}", ...) reaches it.

Identify clients with a token

Cabby can identify a client from a signed token (a JWT) without calling the app's connect. Render it into the page; Cabby verifies it with --jwt_secret, or else --secret:

<%# the layout's head, instead of action_cable_meta_tag %>
<%= action_cable_with_jwt_meta_tag(current_user: current_user) %>
<%# => <meta name="action-cable-url" content="ws://localhost:8080/cable?jid=eyJhbGciOiJIUzI1NiJ9..."> %>

<%# or the token alone, for a client that sends it another way %>
<%= cabby_token_meta_tag(current_user: current_user) %>
<%# => <meta name="cabby-token" content="eyJhbGciOiJIUzI1NiJ9..."> %>
Cabby.jwt(current_user: user)                  # the token itself
Cabby.jwt(current_user: user, ttl: 10.minutes)

Pass the connection's identifiers (its identified_by names) with the values connect would set; they are encoded as connect answers them, so channels see the same current_user either way. A name the connection does not declare is an error. connect is not called for a client with a token, so whatever else it does (tracking a visit, setting state) does not happen; a client without a token goes through connect as before.

Tokens last jwt_ttl (an hour by default). Cabby checks the token when the client connects (an open connection stays open when its token expires), and refuses an expired one with token_expired; the browser client can then fetch a new token and reconnect (refreshToken, below). A token signed with another key gets unauthorized. Without jwt_secret or secret, Cabby.jwt raises Cabby::ConfigurationError.

Turbo

turbo_stream_from and Turbo::StreamsChannel.broadcast_*_to (and broadcasts_to in models) work with no setup: subscriptions go through your app's Turbo::StreamsChannel, broadcasts through the adapter. With bin/rails g cabby:client the page subscribes on the browser client instead (below).

With a secret configured, the gem gives Turbo the key the server's --turbo_streams verifies with (turbo_streams_secret, else streams_secret, else secret, as the server falls back). Run Cabby with --turbo_streams and it confirms Turbo subscriptions itself, without calling the app.

Give Turbo a key of its own, the same CABBY_TURBO_STREAMS_SECRET for the app and the server. With the secret's key, a page's Turbo Streams name is also a $pubsub signed name, which lets its viewer join the stream's presence, and Cabby 0.6 logs at startup:

WRN Turbo Streams signed names are also accepted by $pubsub (the same key verifies them), where they give presence on their stream; set --turbo_streams_secret to a key of its own

cabby:setup sets it up that way. An app set up before 0.5.2 keeps working as it is. To switch, give the app and the server the same new CABBY_TURBO_STREAMS_SECRET (bin/rails secret) where they get CABBY_SECRET: the gem and the server both read the variable (a key kept in the credentials goes in config/cabby.yml as turbo_streams_secret, as cabby:setup writes it). Pages rendered before the switch subscribe again once reloaded.

Set turbo_streams: false to leave Turbo's key alone. A key the app sets itself (config.turbo.signed_stream_verifier_key) is kept; then give Cabby that key with --turbo_streams_secret, or run it without --turbo_streams: if the app sets Turbo.signed_stream_verifier_key after boot, the server's key no longer matches and Cabby rejects those subscriptions.

The browser client

The gem carries @cabby/web, Cabby's browser client (about 3.9 KB gzipped), and its Turbo stream source (about 1.3 KB), as assets. With import maps there is nothing to install: bin/rails g cabby:setup pins the client, bin/rails g cabby:client sets it up.

bin/rails g cabby:client
File What it gets
config/importmap.rb pin "@cabby/web", to: "cabby-web.min.js", pin "@cabby/web/turbo", to: "cabby-web-turbo.min.js" (with Turbo), pin "cabby"
app/javascript/cabby.js The client, on the URL of the layout's action_cable_meta_tag; with Turbo, startTurboStreams
app/javascript/application.js import "cabby", its first import, before @hotwired/turbo-rails
// app/javascript/cabby.js, for an app with Turbo and action_cable_meta_tag
// The app's Cabby client (@cabby/web), on the WebSocket URL the layout renders.
// application.js imports this module before @hotwired/turbo-rails, so turbo_stream_from's
// elements subscribe on this client: one connection, missed Turbo Stream actions applied after a
// reconnect, and its session id sent with Turbo's requests (X-Socket-ID) for to_others: true.
import { createClient } from "@cabby/web"
import { startTurboStreams } from "@cabby/web/turbo"

const url = document.querySelector('meta[name="action-cable-url"]')?.content ?? "/cable"

export const cabby = createClient(url)

startTurboStreams(cabby)

Other modules use the same client:

import { cabby } from "cabby"

const chat = cabby.channel("ChatChannel", { room: "lobby" })
chat.on("message", (data) => console.log(data))

signedStream(name) takes a name from cabby_signed_stream_name. After a short disconnect the client restores its session or asks for the messages it missed; the server needs a broker for that (--broker=memory, for example).

The generator reads the layouts. With action_cable_with_jwt_meta_tag (the token in the URL) the client gets refreshToken: tokenFromPage(), which loads the page again in the background for a new token when the server answers token_expired; with cabby_token_meta_tag it also gets token from that tag. --skip-turbo (the default without turbo-rails) leaves the Turbo part out.

The import goes before every other import of application.js, so the module runs before them all, @hotwired/turbo-rails and anything that imports it included. The generator changes no file when one is not as it expects (no application.js, an application.js that does not import @hotwired/turbo-rails or imports cabby after something else, a cabby.js with other content): it prints the reason and each step to take by hand. When no layout or helper renders action_cable_meta_tag (or action_cable_with_jwt_meta_tag), it says to add one: without it the client connects to /cable on the app's own host. Running it again changes nothing.

Turbo Streams on the browser client

startTurboStreams runs the elements turbo_stream_from renders on the client, in place of Turbo's own Action Cable connection:

  • the page opens one WebSocket, on the extended protocol;
  • after a dropped connection, the Turbo Stream actions broadcast meanwhile are applied once the page reconnects, when the server has a broker (--broker=memory, for example);
  • Turbo's requests (a form submission, for example) carry the client's session id as X-Socket-ID, so to_others: true and Cabby::Rails.broadcasting_to_others leave the page that made the request out of a Turbo broadcast made in that request. A broadcast made in a job still reaches it (to everyone but the sender).

It must run before @hotwired/turbo-rails is evaluated, which is why it lives in a module that application.js imports first: turbo-rails then keeps this element and opens no connection of its own. Run after turbo-rails, startTurboStreams throws an error that says so, and Turbo opens its own connection as before.

Your own fetch calls send the id themselves:

fetch("/messages", { method: "POST", headers: { "X-Socket-ID": cabby.sessionId ?? "" }, body })

Broadcasts made before the page subscribed: since

A page shows the state as of its render, and its turbo_stream_from subscribes a moment later: a broadcast made in between is in neither. With since, the element's first subscribe asks the server for what was broadcast to its stream since the page was rendered, and applies it once.

# config/cabby.yml
default: &default
  turbo_streams_since: true    # or CABBY_TURBO_STREAMS_SINCE=true; off by default
<%= turbo_stream_from @room %>                           <%# as the setting says %>
<%= turbo_stream_from @room, since: true %>              <%# the time of the render %>
<%= turbo_stream_from @room, since: false %>             <%# none, whatever the setting %>
<%= turbo_stream_from @room, since: @messages_loaded_at %> <%# a Time, or unix seconds %>
<turbo-cable-stream-source since="1796043501" channel="Turbo::StreamsChannel" signed-stream-name="...">

The value is whole unix seconds, floored: the broadcasts of the second the page was rendered in can come again, none is lost to rounding. Without since (the setting off and no option) the tag is turbo-rails' own, byte for byte. The attribute is for the browser client's element (cabby:client).

  • The server needs a broker (--broker=memory, for example). Without one every first request is refused, so a page load with since ends with cabby:history { ok: false, initial: true } and the server logs, for each subscribe: WRN couldn't retrieve history ... error="history not supported". Live broadcasts still arrive. That is why the setting is off by default.
  • A Turbo Drive visit to a page with the same stream: a broadcast made while the next page is on its way is applied to that page, once.
  • A turbo_stream_from inside a cache block is cached with its since: a page served from the fragment later asks from the time the fragment was rendered, which repeats broadcasts and finds nothing older than the server's --history_ttl (300 s). Render the tag outside cache blocks.
  • since comes from the app server's clock and the Cabby server compares it with its own: a clock ahead of Cabby's loses the broadcasts of the difference. Keep both on NTP.
  • The rest of what since cannot promise (repeated actions, history the server no longer keeps, elements joining a subscription in use, morphing) is in the client's README.

Each element reports the answer as a cabby:history event that bubbles, with detail { ok, initial }; initial: true marks the answer to the first request, the one since asks. Two ways to react, in a module application.js imports, for a list rendered as <ol id="messages"> next to the turbo_stream_from:

// Load the list again whenever a catch-up fails (a fetch cannot loop)
document.addEventListener("cabby:history", async ({ detail }) => {
  if (detail.ok) return
  const html = await (await fetch(location.href)).text()
  const fresh = new DOMParser().parseFromString(html, "text/html")
  document.querySelector("#messages").replaceWith(fresh.querySelector("#messages"))
})

// Or reload the page, only after a reconnect: a failed first request would fail again
document.addEventListener("cabby:history", ({ detail }) => {
  if (!detail.ok && !detail.initial) location.reload()
})

On a server without a broker, a page with both loads once and fetches itself once.

With a JavaScript bundler

Apps that bundle JavaScript (esbuild, Vite, webpack) install the client: npm install github:DaniG2k/cabby-web#v0.4.1. bin/rails g cabby:client then prints the module to write and its import, import "./cabby", first in application.js, before @hotwired/turbo-rails. @rails/actioncable keeps working too.

Channels and state

Channels and connections run unchanged. A channel instance lives for one call, so values to keep between calls are declared; Cabby holds them:

class ChatChannel < ApplicationCable::Channel
  state_attr_accessor :room

  def subscribed
    self.room = Room.find(params[:id])
    stream_for room
  end

  def speak(data)
    room.messages.create!(text: data["text"])
  end
end

state_attr_accessor works on connections too. Values are JSON; records are stored as GlobalIDs and loaded when read; a string always reads back as a string.

Presence and whispers need no setup in the channel; presence needs a broker (--broker=memory).

class ChatChannel < ApplicationCable::Channel
  def subscribed
    stream_from "chat_#{params[:room]}", whisper: true   # takes whispers, and sends them to the others
    join_presence                                       # on the first stream of this call
  end

  def away = leave_presence

  private

  def user_presence_id = current_user.id                  # sent as a string
  def user_presence_info = { name: current_user.name }    # JSON
end
  • join_presence(stream, id:, info:) and leave_presence(id) take their own values too. Sessions with the same id count once. The stream's subscribers get the join and leave events; the client's presence command lists the members.
  • A member the channel joined is the channel's: that client's own join and leave commands change nothing (Cabby 0.5.9 and later). To let a user leave, call leave_presence in an action.
  • Unsubscribing leaves at once. A dropped connection leaves after --presence_ttl seconds (15). The server keeps a connected member alive only on the extended protocol (@cabby/web); with @rails/actioncable it drops one after the same time.
  • One whisper stream per subscription: the last whisper: true wins, and stopping that stream stops the whispers. Without whisper: true Cabby drops them.
  • A whisper reaches only the subscriptions that take whispers on its stream (whisper: true, or $pubsub with --streams_whisper), never its sender. A Turbo Streams subscription to the same stream, or a channel streaming from it without whisper: true, does not receive it (Cabby 0.6; 0.5 sent it to every subscriber).

What does not work in this model, each call having a new instance:

  • an instance variable set in one call and read in a later one, where it is nil: use state_attr_accessor. Set and read in the same call, it works (@room ||= ... included);
  • periodically timers (the gem logs a warning once per channel class): use a job;
  • stream_from and stream_for with a block, a callback, or a coder other than ActiveSupport::JSON: Cabby sends each broadcast to the clients as it is, so broadcast what they should receive;
  • transmit after the call has answered, from a thread for example;
  • on the connection, an instance variable set in connect and read in a channel's call: use identified_by or state_attr_accessor.

Compatibility checks

Two opt-in checks find the first three in channels. RuboCop cops (Cabby/InstanceVariables, Cabby/PeriodicTimers, Cabby/StreamCallbacks), for development; the gem does not load RuboCop:

bundle exec rubocop -r cabby/rails/rubocop --only Cabby

Or require: [cabby/rails/rubocop] in .rubocop.yml. They check classes whose superclass is ActionCable::Channel::Base or is named ...Channel, wherever they live.

Runtime checks, in development and test:

# config/environments/development.rb, config/environments/test.rb
require "cabby/rails/compatibility"

Such code then raises Cabby::CompatibilityError where it runs, on Cabby and in ActionCable::Channel::TestCase tests, where a channel also stops keeping its instance variables from one call to the next. Code that works is left alone.

Upgrading to Cabby 0.6

Since cabby-rails 0.5.2, bin/cabby and the suggested image are Cabby 0.6.0. What a Rails app may have to change (all of it):

If the app Then
Reads whispers in a channel that streams from the stream without whisper: true Add whisper: true there: a whisper now reaches only the subscriptions that take whispers
Runs 0.5 and 0.6 servers side by side while upgrading --whisper_compat_0_5 on the 0.6 servers until the last 0.5 one is gone
Signs Turbo Streams names with the secret A key of its own, CABBY_TURBO_STREAMS_SECRET (Turbo), or a warning at each start
Relies on a proxy's X-Request-ID being the session id (Cabby::Rails.current_sid, sid= in the logs) --request_id_as_session_id: the server now generates every session id
Connects Cabby to Redis over TLS with a self-signed or private CA certificate --redis_tls_ca_cert_path, or --redis_tls_verify=false: the server now checks the certificate
Has SSE, Durable Streams or Pusher clients that fall more than 1 MiB behind A larger --ws_max_pending_size: they are now disconnected as slow, as Action Cable clients are
Limits NATS reconnects in a server configuration file ([nats]; a 0.5 --print-config wrote 5) Remove the limit: the server now keeps reconnecting, and with one it exits once the attempts run out

Deploying

Run two processes: the app, and cabby next to it.

  • Same CABBY_SECRET for both, and with Turbo the same CABBY_TURBO_STREAMS_SECRET.
  • cabby --rpc_host=http://<app, internal address>/_cabby --secret=$CABBY_SECRET, plus --turbo_streams with Turbo and the --broadcast_adapter you use.
  • CABBY_URL=wss://<the public address of cabby>/cable in the app, so pages point at Cabby.
  • Cabby's health check is GET /health.

Agent skill

The gem carries a skill for coding agents that work on an app using it, in the agent skills format: skills/cabby-rails/SKILL.md and the reference files it points to (setup, channels, broadcasting, tokens, Turbo and the browser client, deploying, testing, troubleshooting, and a check to run in development).

Install it into the app with the skills command line, from the installed gem so that it matches the gem's version (--copy, as the gem's folder changes with each version; run it again after an update):

npx skills add "$(bundle info cabby-rails --path)" --skill cabby-rails --copy

Or point the agent at the file: "$(bundle info cabby-rails --path)/skills/cabby-rails/SKILL.md".

Development

bundle exec rake                                              # tests, then RuboCop
BUNDLE_GEMFILE=gemfiles/rails_8_0.gemfile bundle exec rake    # Rails 8.0

The browser client in app/assets/javascripts (cabby-web.min.js and cabby-web-turbo.min.js) comes from a cabby-web checkout, built with npm run build: bundle exec rake "client:vendor[../cabby-web,0.4.1]" copies both files and records the version and commit in the first line of each.

The end-to-end tests run a real cabby binary: the one on your PATH, or the one CABBY_BIN names (they are skipped without one). The Puma plugin tests run the bundled Puma, and Puma 6 and 7 when they are installed (gem install puma -v "~> 6.0"); bin/cabby's tests serve fake releases locally (CABBY_RELEASES_URL) and list tags from a local git repository, so they need no network. The broadcaster tests start their own redis-server and nats-server on free ports (from the PATH, or REDIS_SERVER_BIN and NATS_SERVER_BIN), and use a cabby_rails_test database on the local PostgreSQL (CABBY_TEST_PGHOST, CABBY_TEST_PGPORT); each is skipped when missing.

License

MIT

About

Rails integration for Cabby, the real-time server: Action Cable connections and channels over HTTP RPC, in pure Ruby

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages