Skip to content

Commit

Permalink
Modernize gem.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed Sep 23, 2024
1 parent 7fb10ee commit 63e5aa2
Show file tree
Hide file tree
Showing 16 changed files with 156 additions and 50 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,9 +33,11 @@ jobs:
- name: Run tests
timeout-minutes: 5
run: bundle exec bake test

- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
with:
include-hidden-files: true
if-no-files-found: error
name: coverage-${{matrix.os}}-${{matrix.ruby}}
path: .covered.db

Expand All @@ -50,7 +52,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
4 changes: 3 additions & 1 deletion gems.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Released under the MIT License.
# Copyright, 2021-2024, by Samuel Williams.

source 'https://rubygems.org'
source "https://rubygems.org"

gemspec

Expand All @@ -17,6 +17,8 @@
group :test do
gem "sus"
gem "covered"
gem "decode"
gem "rubocop"

gem "bake-test"
gem "bake-test-external"
Expand Down
6 changes: 3 additions & 3 deletions lib/live.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@

require_relative "live/version"

require_relative 'live/page'
require_relative 'live/view'
require_relative 'live/resolver'
require_relative "live/page"
require_relative "live/view"
require_relative "live/resolver"
4 changes: 2 additions & 2 deletions lib/live/element.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
# Released under the MIT License.
# Copyright, 2021-2024, by Samuel Williams.

require 'json'
require 'securerandom'
require "json"
require "securerandom"

module Live
class PageError < RuntimeError
Expand Down
24 changes: 12 additions & 12 deletions lib/live/page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
# Released under the MIT License.
# Copyright, 2021-2024, by Samuel Williams.

require_relative 'element'
require_relative 'resolver'
require_relative "element"
require_relative "resolver"

require 'async'
require 'async/queue'
require "async"
require "async/queue"

require 'protocol/websocket'
require 'protocol/websocket/message'
require "protocol/websocket"
require "protocol/websocket/message"

require 'console/event/failure'
require "console/event/failure"

module Live
# Represents a connected client page with bound dynamic content areas.
Expand Down Expand Up @@ -87,23 +87,23 @@ def close
# Process a single incoming message from the network.
def process_message(message)
case message[0]
when 'bind'
when "bind"
# Bind a client-side element to a server-side element.
if element = self.resolve(message[1], message[2])
self.bind(element)
else
Console.warn(self, "Could not resolve element:", message)
@updates.enqueue(['error', message[1], "Could not resolve element!"])
@updates.enqueue(["error", message[1], "Could not resolve element!"])
end
when 'unbind'
when "unbind"
# Unbind a client-side element from a server-side element.
if element = @elements.delete(message[1])
element.close unless @attached.key?(message[1])
else
Console.warn(self, "Could not unbind element:", message)
@updates.enqueue(['error', message[1], "Could not unbind element!"])
@updates.enqueue(["error", message[1], "Could not unbind element!"])
end
when 'event'
when "event"
# Handle an event from the client.
self.handle(message[1], message[2])
else
Expand Down
2 changes: 1 addition & 1 deletion lib/live/resolver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Released under the MIT License.
# Copyright, 2021-2024, by Samuel Williams.

require_relative 'element'
require_relative "element"

module Live
# Resolves a client-side tag into a server-side instance.
Expand Down
2 changes: 1 addition & 1 deletion lib/live/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
# Copyright, 2021-2024, by Samuel Williams.

module Live
VERSION = "0.13.0"
VERSION = "0.13.0"
end
6 changes: 3 additions & 3 deletions lib/live/view.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
# Released under the MIT License.
# Copyright, 2021-2024, by Samuel Williams.

require_relative 'element'
require 'xrb/builder'
require_relative "element"
require "xrb/builder"

module Live
# Represents a single division of content on the page an provides helpers for rendering the content.
class View < Element
# @returns [Object] The generated HTML.
def to_html
XRB::Builder.fragment do |builder|
builder.inline_tag :div, id: @id, class: 'live', data: @data do
builder.inline_tag :div, id: @id, class: "live", data: @data do
render(builder)
end
end
Expand Down
6 changes: 3 additions & 3 deletions live.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ Gem::Specification.new do |spec|
spec.authors = ["Samuel Williams", "Olle Jonsson", "Tatsuhiro Ujihisa"]
spec.license = "MIT"

spec.cert_chain = ['release.cert']
spec.signing_key = File.expand_path('~/.gem/release.pem')
spec.cert_chain = ["release.cert"]
spec.signing_key = File.expand_path("~/.gem/release.pem")

spec.homepage = "https://github.com/socketry/live"

Expand All @@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
"source_code_uri" => "https://github.com/socketry/live.git",
}

spec.files = Dir.glob(['{lib}/**/*', '*.md'], File::FNM_DOTMATCH, base: __dir__)
spec.files = Dir.glob(["{lib}/**/*", "*.md"], File::FNM_DOTMATCH, base: __dir__)

spec.required_ruby_version = ">= 3.1"

Expand Down
2 changes: 1 addition & 1 deletion test/live/element.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 'live/element'
require "live/element"

describe Live::Element do
it "can generate a unique id" do
Expand Down
14 changes: 7 additions & 7 deletions test/live/page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
# Released under the MIT License.
# Copyright, 2021-2024, by Samuel Williams.

require 'live/page'
require 'live/view'
require 'live/resolver'
require "live/page"
require "live/view"
require "live/resolver"

class MyView < Live::View
end
Expand All @@ -15,19 +15,19 @@ class MyView < Live::View

let(:page) {subject.new(resolver)}

with '#resolve' do
with "#resolve" do
it "resolves allowed elements" do
resolver.allowed[Live::View.name] = Live::View

expect(page.resolve('live-view', {class: 'Live::View'})).to be_a(Live::View)
expect(page.resolve("live-view", {class: "Live::View"})).to be_a(Live::View)
end

it "ignores non-allowed elements" do
expect(page.resolve('live-view', {class: 'Live::View'})).to be_nil
expect(page.resolve("live-view", {class: "Live::View"})).to be_nil
end
end

with '#attach' do
with "#attach" do
let(:view) {MyView.new}

it "can resolve attached elements" do
Expand Down
4 changes: 2 additions & 2 deletions test/live/view.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
# Released under the MIT License.
# Copyright, 2024, by Samuel Williams.

require 'live/view'
require "live/view"

describe Live::View do
let(:view) {subject.new('test-id')}
let(:view) {subject.new("test-id")}

with "#to_s" do
it "can generate string representation" do
Expand Down
20 changes: 10 additions & 10 deletions test/live/website.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
# Released under the MIT License.
# Copyright, 2024, by Samuel Williams.

require 'sus/fixtures/async/http/server_context'
require 'sus/fixtures/async/webdriver/session_context'
require "sus/fixtures/async/http/server_context"
require "sus/fixtures/async/webdriver/session_context"

require 'async/websocket'
require 'async/websocket/adapters/http'
require "async/websocket"
require "async/websocket/adapters/http"

require 'protocol/http'
require 'protocol/http/body/file'
require "protocol/http"
require "protocol/http/body/file"

require 'live'
require "live"

class TestResolver < Live::Resolver
def initialize(...)
Expand Down Expand Up @@ -43,7 +43,7 @@ def bind(...)
end

def render(builder)
builder.tag('p') do
builder.tag("p") do
builder.text Time.now.to_s
end
end
Expand Down Expand Up @@ -75,13 +75,13 @@ def app
local_path = File.join(root, request.path)

if File.file?(local_path)
Protocol::HTTP::Response[200, {'content-type' => content_type(local_path)}, ::Protocol::HTTP::Body::File.open(local_path)]
Protocol::HTTP::Response[200, {"content-type" => content_type(local_path)}, ::Protocol::HTTP::Body::File.open(local_path)]
elsif request.path == "/live"
Async::WebSocket::Adapters::HTTP.open(request) do |connection|
Live::Page.new(resolver).run(connection)
end
else
Protocol::HTTP::Response[404, {'content-type' => 'text/plain'}, ["Not found"]]
Protocol::HTTP::Response[404, {"content-type" => "text/plain"}, ["Not found"]]
end
end
end
Expand Down

0 comments on commit 63e5aa2

Please sign in to comment.