Skip to content

Commit af33970

Browse files
committed
Modernize gem.
1 parent 699bdfc commit af33970

27 files changed

+217
-108
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Documentation Coverage
2+
3+
on: [push, pull_request]
4+
5+
permissions:
6+
contents: read
7+
8+
env:
9+
CONSOLE_OUTPUT: XTerm
10+
COVERAGE: PartialSummary
11+
12+
jobs:
13+
validate:
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- uses: actions/checkout@v4
18+
- uses: ruby/setup-ruby@v1
19+
with:
20+
ruby-version: "3.3"
21+
bundler-cache: true
22+
23+
- name: Validate coverage
24+
timeout-minutes: 5
25+
run: bundle exec bake decode:index:coverage lib

.github/workflows/documentation.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040
run: bundle exec bake utopia:project:static --force no
4141

4242
- name: Upload documentation artifact
43-
uses: actions/upload-pages-artifact@v2
43+
uses: actions/upload-pages-artifact@v3
4444
with:
4545
path: docs
4646

@@ -55,4 +55,4 @@ jobs:
5555
steps:
5656
- name: Deploy to GitHub Pages
5757
id: deployment
58-
uses: actions/deploy-pages@v3
58+
uses: actions/deploy-pages@v4

.github/workflows/rubocop.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: RuboCop
2+
3+
on: [push, pull_request]
4+
5+
permissions:
6+
contents: read
7+
8+
env:
9+
CONSOLE_OUTPUT: XTerm
10+
11+
jobs:
12+
check:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- uses: actions/checkout@v4
17+
- uses: ruby/setup-ruby@v1
18+
with:
19+
ruby-version: ruby
20+
bundler-cache: true
21+
22+
- name: Run RuboCop
23+
timeout-minutes: 10
24+
run: bundle exec rubocop

.github/workflows/coverage.yaml renamed to .github/workflows/test-coverage.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Coverage
1+
name: Test Coverage
22

33
on: [push, pull_request]
44

@@ -33,8 +33,8 @@ jobs:
3333
- name: Run tests
3434
timeout-minutes: 5
3535
run: bundle exec bake test
36-
37-
- uses: actions/upload-artifact@v3
36+
37+
- uses: actions/upload-artifact@v4
3838
with:
3939
name: coverage-${{matrix.os}}-${{matrix.ruby}}
4040
path: .covered.db
@@ -50,7 +50,7 @@ jobs:
5050
ruby-version: "3.3"
5151
bundler-cache: true
5252

53-
- uses: actions/download-artifact@v3
53+
- uses: actions/download-artifact@v4
5454

5555
- name: Validate coverage
5656
timeout-minutes: 5

.rubocop.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
AllCops:
2+
DisabledByDefault: true
3+
4+
Layout/IndentationStyle:
5+
Enabled: true
6+
EnforcedStyle: tabs
7+
8+
Layout/InitialIndentation:
9+
Enabled: true
10+
11+
Layout/IndentationWidth:
12+
Enabled: true
13+
Width: 1
14+
15+
Layout/IndentationConsistency:
16+
Enabled: true
17+
EnforcedStyle: normal
18+
19+
Layout/BlockAlignment:
20+
Enabled: true
21+
22+
Layout/EndAlignment:
23+
Enabled: true
24+
EnforcedStyleAlignWith: start_of_line
25+
26+
Layout/BeginEndAlignment:
27+
Enabled: true
28+
EnforcedStyleAlignWith: start_of_line
29+
30+
Layout/ElseAlignment:
31+
Enabled: true
32+
33+
Layout/DefEndAlignment:
34+
Enabled: true
35+
36+
Layout/CaseIndentation:
37+
Enabled: true
38+
39+
Layout/CommentIndentation:
40+
Enabled: true
41+
42+
Layout/EmptyLinesAroundClassBody:
43+
Enabled: true
44+
45+
Layout/EmptyLinesAroundModuleBody:
46+
Enabled: true
47+
48+
Style/FrozenStringLiteralComment:
49+
Enabled: true
50+
51+
Style/StringLiterals:
52+
Enabled: true
53+
EnforcedStyle: double_quotes

async-rest.gemspec

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ Gem::Specification.new do |spec|
1010
spec.authors = ["Samuel Williams", "Olle Jonsson", "Cyril Roelandt", "Terry Kerr"]
1111
spec.license = "MIT"
1212

13-
spec.cert_chain = ['release.cert']
14-
spec.signing_key = File.expand_path('~/.gem/release.pem')
13+
spec.cert_chain = ["release.cert"]
14+
spec.signing_key = File.expand_path("~/.gem/release.pem")
1515

1616
spec.homepage = "https://github.com/socketry/async-rest"
1717

@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
2020
"source_code_uri" => "https://github.com/socketry/async-rest.git",
2121
}
2222

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

2525
spec.required_ruby_version = ">= 3.1"
2626

config/sus.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# frozen_string_literal: true
22

33
# Released under the MIT License.
4-
# Copyright, 2023, by Samuel Williams.
4+
# Copyright, 2023-2024, by Samuel Williams.
55

6-
require 'covered/sus'
6+
require "covered/sus"
77
include Covered::Sus

examples/github/feed.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
# frozen_string_literal: true
33

44
# Released under the MIT License.
5-
# Copyright, 2019-2023, by Samuel Williams.
5+
# Copyright, 2019-2024, by Samuel Williams.
66

7-
require 'async'
8-
require 'async/rest'
9-
require 'async/rest/wrapper/form'
7+
require "async"
8+
require "async/rest"
9+
require "async/rest/wrapper/form"
1010

11-
require 'date'
11+
require "date"
1212

1313
URL = "https://api.github.com"
1414
ENDPOINT = Async::HTTP::Endpoint.parse(URL)
@@ -24,7 +24,7 @@ def initialize
2424
end
2525

2626
def parser_for(response)
27-
if content_type = response.headers['content-type']
27+
if content_type = response.headers["content-type"]
2828
if content_type.start_with? "application/json"
2929
return Async::REST::Wrapper::JSON::Parser
3030
end
@@ -102,7 +102,7 @@ def public_events
102102

103103
puts "Connecting..."
104104
headers = Protocol::HTTP::Headers.new
105-
headers['user-agent'] = "async-rest/GitHub v#{Async::REST::VERSION}"
105+
headers["user-agent"] = "async-rest/GitHub v#{Async::REST::VERSION}"
106106

107107
GitHub::Client.for(ENDPOINT, headers) do |client|
108108
user = client.user("ioquatix")

examples/ollama/ollama.rb

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
#!/usr/bin/env ruby
2+
# frozen_string_literal: true
23

3-
require 'async/rest'
4-
require 'console'
4+
# Released under the MIT License.
5+
# Copyright, 2024, by Samuel Williams.
6+
7+
require "async/rest"
8+
require "console"
59

610
terminal = Console::Terminal.for($stdout)
711
terminal[:reply] = terminal.style(:blue)
@@ -13,11 +17,11 @@ class Wrapper < Async::REST::Wrapper::Generic
1317
APPLICATION_JSON_STREAM = "application/x-ndjson"
1418

1519
def prepare_request(request, payload)
16-
request.headers.add('accept', APPLICATION_JSON)
17-
request.headers.add('accept', APPLICATION_JSON_STREAM)
20+
request.headers.add("accept", APPLICATION_JSON)
21+
request.headers.add("accept", APPLICATION_JSON_STREAM)
1822

1923
if payload
20-
request.headers['content-type'] = APPLICATION_JSON
24+
request.headers["content-type"] = APPLICATION_JSON
2125

2226
request.body = ::Protocol::HTTP::Body::Buffered.new([
2327
::JSON.dump(payload)
@@ -80,7 +84,7 @@ def join
8084
end
8185

8286
def parser_for(response)
83-
case response.headers['content-type']
87+
case response.headers["content-type"]
8488
when APPLICATION_JSON
8589
return Async::REST::Wrapper::JSON::Parser
8690
when APPLICATION_JSON_STREAM
@@ -108,13 +112,13 @@ def generate(prompt, &block)
108112
end
109113

110114
class Client < Async::REST::Resource
111-
ENDPOINT = Async::HTTP::Endpoint.parse('http://localhost:11434')
115+
ENDPOINT = Async::HTTP::Endpoint.parse("http://localhost:11434")
112116

113117
def generate(prompt, **options, &block)
114118
options[:prompt] = prompt
115-
options[:model] ||= 'llama2'
119+
options[:model] ||= "llama2"
116120

117-
Generate.post(self.with(path: '/api/generate'), options, &block)
121+
Generate.post(self.with(path: "/api/generate"), options, &block)
118122
end
119123
end
120124
end

examples/slack/clean.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@
22
# frozen_string_literal: true
33

44
# Released under the MIT License.
5-
# Copyright, 2019-2023, by Samuel Williams.
5+
# Copyright, 2019-2024, by Samuel Williams.
66

7-
require 'pry'
8-
require 'set'
7+
require "pry"
8+
require "set"
99

1010
def rate_limited?(response)
1111
pp response
1212

1313
response[:error] == "ratelimited"
1414
end
1515

16-
require 'async/rest'
16+
require "async/rest"
1717

1818
URL = "https://slack.com/api"
1919
TOKEN = "xoxp-your-api-token"

examples/xkcd/comic.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
# frozen_string_literal: true
33

44
# Released under the MIT License.
5-
# Copyright, 2019-2023, by Samuel Williams.
5+
# Copyright, 2019-2024, by Samuel Williams.
66

7-
require_relative '../../lib/async/rest'
8-
require_relative '../../lib/async/rest/wrapper/url_encoded'
7+
require_relative "../../lib/async/rest"
8+
require_relative "../../lib/async/rest/wrapper/url_encoded"
99

10-
require 'nokogiri'
10+
require "nokogiri"
1111

1212
Async.logger.debug!
1313

@@ -32,7 +32,7 @@ def wrap_response(response)
3232
end
3333

3434
def process_response(request, response)
35-
if content_type = response.headers['content-type']
35+
if content_type = response.headers["content-type"]
3636
if content_type.start_with? TEXT_HTML
3737
wrap_response(response)
3838
else
@@ -54,7 +54,7 @@ def image_url
5454
end
5555

5656
Async do
57-
URL = 'https://xkcd.com/'
57+
URL = "https://xkcd.com/"
5858

5959
Async::REST::Resource.for(URL) do |resource|
6060
(2000..2010).each do |id|

fixtures/wrapper_examples.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
# Released under the MIT License.
44
# Copyright, 2019-2024, by Samuel Williams.
55

6-
require 'sus/fixtures/async/http/server_context'
6+
require "sus/fixtures/async/http/server_context"
77

8-
require 'async/rest/resource'
9-
require 'async/rest/representation'
8+
require "async/rest/resource"
9+
require "async/rest/representation"
1010

1111
AWrapper = Sus::Shared("a wrapper") do
1212
include Sus::Fixtures::Async::HTTP::ServerContext
@@ -16,7 +16,7 @@
1616

1717
let(:middleware) do
1818
Protocol::HTTP::Middleware.for do |request|
19-
if request.headers['content-type'] == wrapper.content_type
19+
if request.headers["content-type"] == wrapper.content_type
2020
# Echo it back:
2121
Protocol::HTTP::Response[200, request.headers, request.body]
2222
else

gems.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Released under the MIT License.
44
# Copyright, 2018-2024, by Samuel Williams.
55

6-
source 'https://rubygems.org'
6+
source "https://rubygems.org"
77

88
gemspec
99

@@ -16,8 +16,11 @@
1616

1717
group :test do
1818
gem "sus"
19-
gem "sus-fixtures-async-http"
2019
gem "covered"
20+
gem "decode"
21+
gem "rubocop"
22+
23+
gem "sus-fixtures-async-http"
2124

2225
gem "bake-test"
2326
gem "bake-test-external"

lib/async/rest.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# frozen_string_literal: true
22

33
# Released under the MIT License.
4-
# Copyright, 2018-2023, by Samuel Williams.
4+
# Copyright, 2018-2024, by Samuel Williams.
55

6-
require_relative 'rest/version'
7-
require_relative 'rest/representation'
6+
require_relative "rest/version"
7+
require_relative "rest/representation"

lib/async/rest/representation.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# frozen_string_literal: true
22

33
# Released under the MIT License.
4-
# Copyright, 2018-2023, by Samuel Williams.
4+
# Copyright, 2018-2024, by Samuel Williams.
55
# Copyright, 2021, by Terry Kerr.
66

7-
require_relative 'error'
8-
require_relative 'resource'
9-
require_relative 'wrapper/json'
7+
require_relative "error"
8+
require_relative "resource"
9+
require_relative "wrapper/json"
1010

1111
module Async
1212
module REST

0 commit comments

Comments
 (0)