Skip to content

Commit

Permalink
Modernize gem.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed May 10, 2024
1 parent 48815d7 commit db0a370
Show file tree
Hide file tree
Showing 26 changed files with 565 additions and 331 deletions.
9 changes: 9 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
root = true

[*]
indent_style = tab
indent_size = 2

[*.{yml,yaml}]
indent_style = space
indent_size = 2
57 changes: 57 additions & 0 deletions .github/workflows/coverage.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Coverage

on: [push, pull_request]

permissions:
contents: read

env:
CONSOLE_OUTPUT: XTerm
COVERAGE: PartialSummary

jobs:
test:
name: ${{matrix.ruby}} on ${{matrix.os}}
runs-on: ${{matrix.os}}-latest

strategy:
matrix:
os:
- ubuntu
- macos

ruby:
- "3.3"

steps:
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{matrix.ruby}}
bundler-cache: true

- name: Run tests
timeout-minutes: 5
run: bundle exec bake test

- uses: actions/upload-artifact@v3
with:
name: coverage-${{matrix.os}}-${{matrix.ruby}}
path: .covered.db

validate:
needs: test
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
ruby-version: "3.3"
bundler-cache: true

- uses: actions/download-artifact@v3

- name: Validate coverage
timeout-minutes: 5
run: bundle exec bake covered:validate --paths */.covered.db \;
58 changes: 58 additions & 0 deletions .github/workflows/documentation.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Documentation

on:
push:
branches:
- main

# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages:
permissions:
contents: read
pages: write
id-token: write

# Allow one concurrent deployment:
concurrency:
group: "pages"
cancel-in-progress: true

env:
CONSOLE_OUTPUT: XTerm
BUNDLE_WITH: maintenance

jobs:
generate:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- uses: ruby/setup-ruby@v1
with:
ruby-version: "3.3"
bundler-cache: true

- name: Installing packages
run: sudo apt-get install wget

- name: Generate documentation
timeout-minutes: 5
run: bundle exec bake utopia:project:static --force no

- name: Upload documentation artifact
uses: actions/upload-pages-artifact@v3
with:
path: docs

deploy:
runs-on: ubuntu-latest

environment:
name: github-pages
url: ${{steps.deployment.outputs.page_url}}

needs: generate
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
36 changes: 36 additions & 0 deletions .github/workflows/test-external.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Test External

on: [push, pull_request]

permissions:
contents: read

env:
CONSOLE_OUTPUT: XTerm

jobs:
test:
name: ${{matrix.ruby}} on ${{matrix.os}}
runs-on: ${{matrix.os}}-latest

strategy:
matrix:
os:
- ubuntu
- macos

ruby:
- "3.1"
- "3.2"
- "3.3"

steps:
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{matrix.ruby}}
bundler-cache: true

- name: Run tests
timeout-minutes: 10
run: bundle exec bake test:external
50 changes: 50 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Test

on: [push, pull_request]

permissions:
contents: read

env:
CONSOLE_OUTPUT: XTerm

jobs:
test:
name: ${{matrix.ruby}} on ${{matrix.os}}
runs-on: ${{matrix.os}}-latest
continue-on-error: ${{matrix.experimental}}

strategy:
matrix:
os:
- ubuntu
- macos

ruby:
- "3.1"
- "3.2"
- "3.3"

experimental: [false]

include:
- os: ubuntu
ruby: truffleruby
experimental: true
- os: ubuntu
ruby: jruby
experimental: true
- os: ubuntu
ruby: head
experimental: true

steps:
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{matrix.ruby}}
bundler-cache: true

- name: Run tests
timeout-minutes: 10
run: bundle exec bake test
7 changes: 5 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
/Gemfile.lock
/roda-websockets-*.gem
/.bundle/
/pkg/
/gems.locked
/.covered.db
/external
1 change: 1 addition & 0 deletions .mailmap
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Jeffrey Lim <jf@users.noreply.github.com>
5 changes: 0 additions & 5 deletions CHANGELOG.md

This file was deleted.

5 changes: 0 additions & 5 deletions Gemfile

This file was deleted.

18 changes: 0 additions & 18 deletions LICENSE

This file was deleted.

14 changes: 0 additions & 14 deletions Rakefile

This file was deleted.

4 changes: 4 additions & 0 deletions config/sus.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# frozen_string_literal: true

require 'covered/sus'
include Covered::Sus
34 changes: 19 additions & 15 deletions examples/echo_server/client.rb
Original file line number Diff line number Diff line change
@@ -1,28 +1,32 @@
# frozen_string_literal: true

# Released under the MIT License.
# Copyright, 2019, by Shannon Skipper.
# Copyright, 2024, by Samuel Williams.

require 'async'
require 'async/http/endpoint'
require 'async/websocket/client'

module Client
URL = 'https://localhost:9292'
ENDPOINT = Async::HTTP::Endpoint.parse URL
MESSAGE = ARGV.first || 'ping'
URL = 'https://localhost:9292'
ENDPOINT = Async::HTTP::Endpoint.parse URL
MESSAGE = ARGV.first || 'ping'

module_function
module_function

def call
Async do
Async::WebSocket::Client.connect ENDPOINT do |connection|
puts "Sending message: #{MESSAGE}"
connection.write MESSAGE
connection.flush
def call
Async do
Async::WebSocket::Client.connect ENDPOINT do |connection|
puts "Sending message: #{MESSAGE}"
connection.write MESSAGE
connection.flush

message = connection.read
puts "Receiving message: #{message}"
end
end
end
message = connection.read
puts "Receiving message: #{message}"
end
end
end
end

Client.call
36 changes: 19 additions & 17 deletions examples/echo_server/config.ru
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,27 @@
require 'roda'

class App < Roda
plugin :websockets
plugin :websockets

def on_message(connection)
Async do |task|
message = connection.read
task.sleep(3) # Async I/O here
connection.write(message)
connection.flush
connection.close
end
end
def on_message(connection)
Async do |task|
message = connection.read

sleep(3) # Async I/O here

connection.write(message)
connection.flush
connection.close
end
end

route do |r|
r.is '' do
r.websocket do |connection|
on_message(connection).wait
end
end
end
route do |r|
r.is '' do
r.websocket do |connection|
on_message(connection).wait
end
end
end
end

run App.freeze.app
Loading

0 comments on commit db0a370

Please sign in to comment.