Skip to content

Commit 6b7ae68

Browse files
committed
Modernize gem.
1 parent 43940ca commit 6b7ae68

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+549
-543
lines changed

.github/workflows/test-coverage.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ jobs:
3636

3737
- uses: actions/upload-artifact@v4
3838
with:
39+
include-hidden-files: true
40+
if-no-files-found: error
3941
name: coverage-${{matrix.os}}-${{matrix.ruby}}
4042
path: .covered.db
4143

.rubocop.yml

+4
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,7 @@ Layout/EmptyLinesAroundModuleBody:
4747

4848
Style/FrozenStringLiteralComment:
4949
Enabled: true
50+
51+
Style/StringLiterals:
52+
Enabled: true
53+
EnforcedStyle: double_quotes

async-http.gemspec

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ Gem::Specification.new do |spec|
1010
spec.authors = ["Samuel Williams", "Brian Morearty", "Bruno Sutic", "Janko Marohnić", "Thomas Morgan", "Adam Daniels", "Igor Sidorov", "Anton Zhuravsky", "Cyril Roelandt", "Denis Talakevich", "Hal Brodigan", "Ian Ker-Seymer", "Josh Huber", "Marco Concetto Rudilosso", "Olle Jonsson", "Orgad Shaneh", "Sam Shadwell", "Stefan Wrobel", "Tim Meusel", "Trevor Turk", "Viacheslav Koval", "dependabot[bot]"]
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-http"
1717

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

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

2525
spec.required_ruby_version = ">= 3.1"
2626

bake.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
#
88
# @parameter version [String] The new version number.
99
def after_gem_release_version_increment(version)
10-
context['releases:update'].call(version)
11-
context['utopia:project:readme:update'].call
10+
context["releases:update"].call(version)
11+
context["utopia:project:readme:update"].call
1212
end

bake/async/http.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
# frozen_string_literal: true
22

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

66
# Fetch the specified URL and print the response.
77
# @param url [String] the URL to parse and fetch.
88
# @param method [String] the HTTP method to use.
99
def fetch(url, method:)
10-
require 'async/http/internet'
11-
require 'kernel/sync'
10+
require "async/http/internet"
11+
require "kernel/sync"
1212

1313
terminal = Console::Terminal.for($stdout)
1414
terminal[:request] = terminal.style(:blue, nil, :bold)

bake/async/http/h2spec.rb

+6-6
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,20 @@ def test
2121
private
2222

2323
def server
24-
require 'async'
25-
require 'async/container'
26-
require 'async/http/server'
27-
require 'io/endpoint/host_endpoint'
24+
require "async"
25+
require "async/container"
26+
require "async/http/server"
27+
require "io/endpoint/host_endpoint"
2828

29-
endpoint = IO::Endpoint.tcp('127.0.0.1', 7272)
29+
endpoint = IO::Endpoint.tcp("127.0.0.1", 7272)
3030

3131
container = Async::Container.new
3232

3333
Console.logger.info(self){"Starting server..."}
3434

3535
container.run(count: 1) do
3636
server = Async::HTTP::Server.for(endpoint, protocol: Async::HTTP::Protocol::HTTP2, scheme: "https") do |request|
37-
Protocol::HTTP::Response[200, {'content-type' => 'text/plain'}, ["Hello World"]]
37+
Protocol::HTTP::Response[200, {"content-type" => "text/plain"}, ["Hello World"]]
3838
end
3939

4040
Async do

config/sus.rb

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
# frozen_string_literal: true
22

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

7-
ENV['CONSOLE_LEVEL'] ||= 'fatal'
7+
ENV["CONSOLE_LEVEL"] ||= "fatal"
88

9-
require 'covered/sus'
9+
require "covered/sus"
1010
include Covered::Sus
1111

12-
require 'traces'
13-
ENV['TRACES_BACKEND'] ||= 'traces/backend/test'
12+
require "traces"
13+
ENV["TRACES_BACKEND"] ||= "traces/backend/test"

examples/compare/benchmark.rb

+7-7
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22
# frozen_string_literal: true
33

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

7-
require 'benchmark'
7+
require "benchmark"
88

9-
require 'httpx'
9+
require "httpx"
1010

11-
require 'async'
12-
require 'async/barrier'
13-
require 'async/semaphore'
14-
require 'async/http/internet'
11+
require "async"
12+
require "async/barrier"
13+
require "async/semaphore"
14+
require "async/http/internet"
1515

1616
URL = "https://www.codeotaku.com/index"
1717
REPEATS = 10

examples/download/chunked.rb

+9-9
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,22 @@
22
# frozen_string_literal: true
33

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

7-
require 'async'
8-
require 'async/clock'
9-
require 'async/barrier'
10-
require 'async/semaphore'
11-
require_relative '../../lib/async/http/endpoint'
12-
require_relative '../../lib/async/http/client'
7+
require "async"
8+
require "async/clock"
9+
require "async/barrier"
10+
require "async/semaphore"
11+
require_relative "../../lib/async/http/endpoint"
12+
require_relative "../../lib/async/http/client"
1313

1414
Async do
1515
url = "https://static.openfoodfacts.org/data/en.openfoodfacts.org.products.csv"
1616

1717
endpoint = Async::HTTP::Endpoint.parse(url)
1818
client = Async::HTTP::Client.new(endpoint)
1919

20-
headers = {'user-agent' => 'curl/7.69.1', 'accept' => '*/*'}
20+
headers = {"user-agent" => "curl/7.69.1", "accept" => "*/*"}
2121

2222
file = File.open("products.csv", "w")
2323
Console.logger.info(self) {"Saving download to #{Dir.pwd}"}
@@ -27,7 +27,7 @@
2727
content_length = nil
2828

2929
if response.success?
30-
unless response.headers['accept-ranges'].include?('bytes')
30+
unless response.headers["accept-ranges"].include?("bytes")
3131
raise "Does not advertise support for accept-ranges: bytes!"
3232
end
3333

examples/fetch/config.ru

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# frozen_string_literal: true
22

3-
require 'rack'
3+
require "rack"
44

55
class Echo
66
def initialize(app)
@@ -24,6 +24,6 @@ end
2424

2525
use Echo
2626

27-
use Rack::Static, :urls => [''], :root => 'public', :index => 'index.html'
27+
use Rack::Static, :urls => [""], :root => "public", :index => "index.html"
2828

2929
run lambda{|env| [404, {}, []]}

examples/fetch/gems.rb

+3-3
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-
gem 'rack'
7-
gem 'falcon'
6+
gem "rack"
7+
gem "falcon"

examples/google/codeotaku.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
URL = "https://www.codeotaku.com/index"
1313
ENDPOINT = Async::HTTP::Endpoint.parse(URL)
1414

15-
if count = ENV['COUNT']&.to_i
15+
if count = ENV["COUNT"]&.to_i
1616
terms = terms.first(count)
1717
end
1818

examples/google/multiple.rb

+5-5
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, 2023, by Samuel Williams.
5+
# Copyright, 2023-2024, by Samuel Williams.
66

7-
require 'async'
8-
require 'async/barrier'
9-
require 'async/semaphore'
10-
require 'async/http/internet'
7+
require "async"
8+
require "async/barrier"
9+
require "async/semaphore"
10+
require "async/http/internet"
1111

1212
TOPICS = ["ruby", "python", "rust"]
1313

examples/google/search.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def search(term)
2222

2323
terms = %w{thoughtful fear size payment lethal modern recognise face morning sulky mountainous contain science snow uncle skirt truthful door travel snails closed rotten halting creator teeny-tiny beautiful cherries unruly level follow strip team things suggest pretty warm end cannon bad pig consider airport strengthen youthful fog three walk furry pickle moaning fax book ruddy sigh plate cakes shame stem faulty bushes dislike train sleet one colour behavior bitter suit count loutish squeak learn watery orange idiotic seat wholesale omniscient nostalgic arithmetic instruct committee puffy program cream cake whistle rely encourage war flagrant amusing fluffy prick utter wacky occur daily son check}
2424

25-
if count = ENV.fetch('COUNT', 20)&.to_i
25+
if count = ENV.fetch("COUNT", 20)&.to_i
2626
terms = terms.first(count)
2727
end
2828

@@ -40,10 +40,10 @@ def search(term)
4040
end
4141
end.map(&:wait).to_h
4242

43-
Console.logger.info(self, name: 'counts') {counts}
43+
Console.logger.info(self, name: "counts") {counts}
4444
end
4545

46-
Console.logger.info(self, name: 'duration') {duration}
46+
Console.logger.info(self, name: "duration") {duration}
4747
ensure
4848
google.close
4949
end

examples/header-lowercase/benchmark.rb

+12-12
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Released under the MIT License.
44
# Copyright, 2023-2024, by Samuel Williams.
55

6-
require 'benchmark/ips'
6+
require "benchmark/ips"
77

88
class NormalizedHeaders
99
def initialize(fields)
@@ -26,23 +26,23 @@ def [](key)
2626
end
2727

2828
FIELDS = {
29-
'content-type' => 'text/html',
30-
'content-length' => '127889',
31-
'accept-ranges' => 'bytes',
32-
'date' => 'Tue, 14 Jul 2015 22:00:02 GMT',
33-
'via' => '1.1 varnish',
34-
'age' => '0',
35-
'connection' => 'keep-alive',
36-
'x-served-by' => 'cache-iad2125-IAD',
29+
"content-type" => "text/html",
30+
"content-length" => "127889",
31+
"accept-ranges" => "bytes",
32+
"date" => "Tue, 14 Jul 2015 22:00:02 GMT",
33+
"via" => "1.1 varnish",
34+
"age" => "0",
35+
"connection" => "keep-alive",
36+
"x-served-by" => "cache-iad2125-IAD",
3737
}
3838

3939
NORMALIZED_HEADERS = NormalizedHeaders.new(FIELDS)
4040
HEADERS = Headers.new(FIELDS)
4141

4242
Benchmark.ips do |x|
43-
x.report('NormalizedHeaders[Content-Type]') { NORMALIZED_HEADERS['Content-Type'] }
44-
x.report('NormalizedHeaders[content-type]') { NORMALIZED_HEADERS['content-type'] }
45-
x.report('Headers') { HEADERS['content-type'] }
43+
x.report("NormalizedHeaders[Content-Type]") { NORMALIZED_HEADERS["Content-Type"] }
44+
x.report("NormalizedHeaders[content-type]") { NORMALIZED_HEADERS["content-type"] }
45+
x.report("Headers") { HEADERS["content-type"] }
4646

4747
x.compare!
4848
end

examples/hello/config.ru

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#!/usr/bin/env falcon --verbose serve -c
22
# frozen_string_literal: true
33

4-
require 'async'
5-
require 'async/barrier'
6-
require 'net/http'
7-
require 'uri'
4+
require "async"
5+
require "async/barrier"
6+
require "net/http"
7+
require "uri"
88

99
run do |env|
1010
i = 1_000_000

examples/licenses/gemspect.rb

+11-11
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, 2020-2023, by Samuel Williams.
5+
# Copyright, 2020-2024, by Samuel Williams.
66

7-
require 'csv'
8-
require 'json'
9-
require 'net/http'
7+
require "csv"
8+
require "json"
9+
require "net/http"
1010

11-
require 'protocol/http/header/authorization'
11+
require "protocol/http/header/authorization"
1212

1313
class RateLimitingError < StandardError; end
1414

15-
@user = ENV['GITHUB_USER']
16-
@token = ENV['GITHUB_TOKEN']
15+
@user = ENV["GITHUB_USER"]
16+
@token = ENV["GITHUB_TOKEN"]
1717

1818
unless @user && @token
1919
fail "export GITHUB_USER and GITHUB_TOKEN!"
@@ -26,16 +26,16 @@ def fetch_github_license(homepage_uri)
2626
url = URI.parse("https://api.github.com/repos/#{owner}/#{repo}/license")
2727
request = Net::HTTP::Get.new(url)
2828

29-
request['user-agent'] = 'fetch-github-licenses'
30-
request['authorization'] = Protocol::HTTP::Header::Authorization.basic(@user, @token)
29+
request["user-agent"] = "fetch-github-licenses"
30+
request["authorization"] = Protocol::HTTP::Header::Authorization.basic(@user, @token)
3131

3232
response = Net::HTTP.start(url.hostname) do |http|
3333
http.request(request)
3434
end
3535

3636
case response
3737
when Net::HTTPOK
38-
JSON.parse(response.body).dig('license', 'spdx_id')
38+
JSON.parse(response.body).dig("license", "spdx_id")
3939
when Net::HTTPNotFound, Net::HTTPMovedPermanently, Net::HTTPForbidden
4040
nil
4141
else
@@ -50,7 +50,7 @@ def fetch_rubygem_license(name, version)
5050
case response
5151
when Net::HTTPOK
5252
body = JSON.parse(response.body)
53-
[name, body.dig('licenses', 0) || fetch_github_license(body['homepage_uri'])]
53+
[name, body.dig("licenses", 0) || fetch_github_license(body["homepage_uri"])]
5454
when Net::HTTPNotFound
5555
[name, nil] # from a non rubygems remote
5656
when Net::HTTPTooManyRequests

0 commit comments

Comments
 (0)