Skip to content

Commit

Permalink
Modernize gem.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed Sep 11, 2024
1 parent 8a1b0d6 commit ad1a257
Show file tree
Hide file tree
Showing 45 changed files with 243 additions and 139 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/documentation-coverage.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Documentation Coverage

on: [push, pull_request]

permissions:
contents: read

env:
CONSOLE_OUTPUT: XTerm
COVERAGE: PartialSummary

jobs:
validate:
runs-on: ubuntu-latest

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

- name: Validate coverage
timeout-minutes: 5
run: bundle exec bake decode:index:coverage lib
24 changes: 24 additions & 0 deletions .github/workflows/rubocop.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: RuboCop

on: [push, pull_request]

permissions:
contents: read

env:
CONSOLE_OUTPUT: XTerm

jobs:
check:
runs-on: ubuntu-latest

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

- name: Run RuboCop
timeout-minutes: 10
run: bundle exec rubocop
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Coverage
name: Test Coverage

on: [push, pull_request]

Expand Down Expand Up @@ -33,8 +33,8 @@ jobs:
- name: Run tests
timeout-minutes: 5
run: bundle exec bake test

- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
with:
name: coverage-${{matrix.os}}-${{matrix.ruby}}
path: .covered.db
Expand All @@ -50,7 +50,7 @@ jobs:
ruby-version: "3.3"
bundler-cache: true

- uses: actions/download-artifact@v3
- uses: actions/download-artifact@v4

- name: Validate coverage
timeout-minutes: 5
Expand Down
53 changes: 53 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
AllCops:
DisabledByDefault: true

Layout/IndentationStyle:
Enabled: true
EnforcedStyle: tabs

Layout/InitialIndentation:
Enabled: true

Layout/IndentationWidth:
Enabled: true
Width: 1

Layout/IndentationConsistency:
Enabled: true
EnforcedStyle: normal

Layout/BlockAlignment:
Enabled: true

Layout/EndAlignment:
Enabled: true
EnforcedStyleAlignWith: start_of_line

Layout/BeginEndAlignment:
Enabled: true
EnforcedStyleAlignWith: start_of_line

Layout/ElseAlignment:
Enabled: true

Layout/DefEndAlignment:
Enabled: true

Layout/CaseIndentation:
Enabled: true

Layout/CommentIndentation:
Enabled: true

Layout/EmptyLinesAroundClassBody:
Enabled: true

Layout/EmptyLinesAroundModuleBody:
Enabled: true

Style/FrozenStringLiteralComment:
Enabled: true

Style/StringLiterals:
Enabled: true
EnforcedStyle: double_quotes
23 changes: 12 additions & 11 deletions autobahn-tests/autobahn-echo-server.ru
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
#!/usr/bin/env -S falcon serve --bind http://127.0.0.1:9001 --count 1 -c
# frozen_string_literal: true

require "async/websocket/adapters/rack"

# TODO: This should probably be part of the library long-term
class RawConnection < Async::WebSocket::Connection
def parse(buffer)
buffer
end
def parse(buffer)
buffer
end

def dump(buffer)
buffer
end
def dump(buffer)
buffer
end
end

app = lambda do |env|
Async::WebSocket::Adapters::Rack.open(env, handler: RawConnection) do |c|
while message = c.read
c.write(message)
end
end or [404, {}, []]
Async::WebSocket::Adapters::Rack.open(env, handler: RawConnection) do |c|
while message = c.read
c.write(message)
end
end or [404, {}, []]
end

run app
20 changes: 10 additions & 10 deletions benchmark/mask_xor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,26 @@ def mask_xor_string(data, mask)
return result
end

require 'benchmark/ips'
require 'securerandom'
require "benchmark/ips"
require "securerandom"

MASK = SecureRandom.bytes(4)
DATA = SecureRandom.bytes(1024 * 1024)

Benchmark.ips do |x|
# Configure the number of seconds used during
# the warmup phase (default 2) and calculation phase (default 5)
x.config(:time => 5, :warmup => 2)
# Configure the number of seconds used during
# the warmup phase (default 2) and calculation phase (default 5)
x.config(:time => 5, :warmup => 2)

# These parameters can also be configured this way
x.time = 5
x.warmup = 2
# These parameters can also be configured this way
x.time = 5
x.warmup = 2

x.report("IO::Buffer") {mask_xor_buffer(DATA, MASK)}
x.report("String") {mask_xor_string(DATA, MASK)}

# Compare the iterations per second of the various reports!
x.compare!
# Compare the iterations per second of the various reports!
x.compare!
end

# Warming up --------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion config/sus.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
# Released under the MIT License.
# Copyright, 2022-2023, by Samuel Williams.

require 'covered/sus'
require "covered/sus"
include Covered::Sus
4 changes: 2 additions & 2 deletions fixtures/protocol/websocket/a_websocket_frame.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
# Released under the MIT License.
# Copyright, 2019-2024, by Samuel Williams.

require 'socket'
require "socket"

module Protocol
module WebSocket
AWebSocketFrame = Sus::Shared("a websocket frame") do
require 'protocol/websocket/framer'
require "protocol/websocket/framer"

let(:sockets) {Socket.pair(Socket::PF_UNIX, Socket::SOCK_STREAM)}

Expand Down
2 changes: 2 additions & 0 deletions gems.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
group :test do
gem "sus"
gem "covered"
gem "decode"
gem "rubocop"

gem "sus-fixtures-async"
gem "sus-fixtures-async-http"
Expand Down
8 changes: 4 additions & 4 deletions lib/protocol/websocket.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Released under the MIT License.
# Copyright, 2019-2024, by Samuel Williams.

require_relative 'websocket/version'
require_relative 'websocket/framer'
require_relative 'websocket/connection'
require_relative 'websocket/message'
require_relative "websocket/version"
require_relative "websocket/framer"
require_relative "websocket/connection"
require_relative "websocket/message"
4 changes: 2 additions & 2 deletions lib/protocol/websocket/binary_frame.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
# Copyright, 2019-2024, by Samuel Williams.
# Copyright, 2021, by Aurora Nockert.

require_relative 'frame'
require_relative 'message'
require_relative "frame"
require_relative "message"

module Protocol
module WebSocket
Expand Down
2 changes: 1 addition & 1 deletion lib/protocol/websocket/close_frame.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Copyright, 2019-2024, by Samuel Williams.
# Copyright, 2021, by Aurora Nockert.

require_relative 'frame'
require_relative "frame"

module Protocol
module WebSocket
Expand Down
2 changes: 1 addition & 1 deletion lib/protocol/websocket/coder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Released under the MIT License.
# Copyright, 2024, by Samuel Williams.

require_relative 'coder/json'
require_relative "coder/json"

module Protocol
module WebSocket
Expand Down
2 changes: 1 addition & 1 deletion lib/protocol/websocket/coder/json.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Released under the MIT License.
# Copyright, 2024, by Samuel Williams.

require 'json'
require "json"

module Protocol
module WebSocket
Expand Down
5 changes: 2 additions & 3 deletions lib/protocol/websocket/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
# Copyright, 2019, by William T. Nelson.
# Copyright, 2021, by Aurora Nockert.

require_relative 'framer'
require 'securerandom'
require_relative "framer"

module Protocol
module WebSocket
Expand Down Expand Up @@ -267,7 +266,7 @@ def send_close(code = Error::NO_ERROR, reason = "")
def write(message, **options)
case message
when String
# This is a compatibility shim for the previous implementation. We may want to eventually deprecate this use case... or maybe it's convenient enough to leave it around.
# This is a compatibility shim for the previous implementation. We may want to eventually deprecate this use case... or maybe it's convenient enough to leave it around.
if message.encoding == Encoding::UTF_8
return send_text(message, **options)
else
Expand Down
2 changes: 1 addition & 1 deletion lib/protocol/websocket/continuation_frame.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Released under the MIT License.
# Copyright, 2019-2024, by Samuel Williams.

require_relative 'frame'
require_relative "frame"

module Protocol
module WebSocket
Expand Down
2 changes: 1 addition & 1 deletion lib/protocol/websocket/error.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Released under the MIT License.
# Copyright, 2019-2024, by Samuel Williams.

require 'protocol/http/error'
require "protocol/http/error"

module Protocol
module WebSocket
Expand Down
12 changes: 6 additions & 6 deletions lib/protocol/websocket/extension/compression.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
# Released under the MIT License.
# Copyright, 2022-2024, by Samuel Williams.

require_relative 'compression/constants'
require_relative 'compression/inflate'
require_relative 'compression/deflate'
require_relative "compression/constants"
require_relative "compression/inflate"
require_relative "compression/deflate"

module Protocol
module WebSocket
Expand All @@ -22,13 +22,13 @@ def self.offer(client_max_window_bits: true, server_max_window_bits: true, clien
when 8..15
header << "client_max_window_bits=#{client_max_window_bits}"
when true
header << 'client_max_window_bits'
header << "client_max_window_bits"
else
raise ArgumentError, "Invalid local maximum window bits!"
end

if client_no_context_takeover
header << 'client_no_context_takeover'
header << "client_no_context_takeover"
end

case server_max_window_bits
Expand All @@ -41,7 +41,7 @@ def self.offer(client_max_window_bits: true, server_max_window_bits: true, clien
end

if server_no_context_takeover
header << 'server_no_context_takeover'
header << "server_no_context_takeover"
end

return header
Expand Down
4 changes: 2 additions & 2 deletions lib/protocol/websocket/extension/compression/constants.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
# Released under the MIT License.
# Copyright, 2022-2023, by Samuel Williams.

require 'zlib'
require "zlib"

module Protocol
module WebSocket
module Extension
module Compression
NAME = 'permessage-deflate'
NAME = "permessage-deflate"

# Zlib is not capable of handling < 9 window bits.
MINIMUM_WINDOW_BITS = 9
Expand Down
2 changes: 1 addition & 1 deletion lib/protocol/websocket/extension/compression/deflate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Released under the MIT License.
# Copyright, 2022-2023, by Samuel Williams.

require_relative 'constants'
require_relative "constants"

module Protocol
module WebSocket
Expand Down
Loading

0 comments on commit ad1a257

Please sign in to comment.