Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add RBS signatures #9

Merged
merged 1 commit into from
Jul 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,22 @@ on:
push:

jobs:
build:
rspec:
runs-on: ubuntu-latest

strategy:
matrix:
ruby:
- 3.1.6
- 3.2.4
- 3.3.3

steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v4

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

- run: bundle exec rake
- run: bundle exec rake
33 changes: 33 additions & 0 deletions .github/workflows/typing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Typing

on:
push:

jobs:
rbs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

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

- run: rbs collection install
- run: bundle exec rbs -I sig validate

steep:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

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

- run: rbs collection install
- run: bundle exec steep check
5 changes: 2 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
.rspec_status
/.bundle/
/.gem_rbs_collection/
/.yardoc
/_yardoc/
/coverage/
/doc/
/pkg/
/spec/reports/
/tmp/

# rspec failure tracking
.rspec_status
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@ gemspec

gem 'rackup'
gem 'rake'
gem 'rbs'
gem 'rspec'
gem 'steep'
gem 'webrick'
63 changes: 63 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,55 @@ PATH
GEM
remote: https://rubygems.org/
specs:
activesupport (7.1.3.4)
base64
bigdecimal
concurrent-ruby (~> 1.0, >= 1.0.2)
connection_pool (>= 2.2.5)
drb
i18n (>= 1.6, < 2)
minitest (>= 5.1)
mutex_m
tzinfo (~> 2.0)
ast (2.4.2)
base64 (0.2.0)
bigdecimal (3.1.8)
concurrent-ruby (1.3.3)
connection_pool (2.4.1)
csv (3.3.0)
diff-lcs (1.5.1)
drb (2.2.1)
ffi (1.17.0)
ffi (1.17.0-x86_64-linux-gnu)
fileutils (1.7.2)
i18n (1.14.5)
concurrent-ruby (~> 1.0)
json (2.7.2)
language_server-protocol (3.17.0.3)
listen (3.9.0)
rb-fsevent (~> 0.10, >= 0.10.3)
rb-inotify (~> 0.9, >= 0.9.10)
logger (1.6.0)
mini_mime (1.1.5)
minitest (5.24.1)
mutex_m (0.2.0)
net-http (0.4.1)
uri
parser (3.3.3.0)
ast (~> 2.4.1)
racc
racc (1.8.0)
rack (3.1.6)
rackup (2.1.0)
rack (>= 3)
webrick (~> 1.8)
rainbow (3.1.1)
rake (13.2.1)
rb-fsevent (0.11.2)
rb-inotify (0.11.1)
ffi (~> 1.0)
rbs (3.5.1)
logger
rspec (3.13.0)
rspec-core (~> 3.13.0)
rspec-expectations (~> 3.13.0)
Expand All @@ -35,7 +74,29 @@ GEM
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.13.0)
rspec-support (3.13.1)
securerandom (0.3.1)
singleton (0.2.0)
steep (1.7.1)
activesupport (>= 5.1)
concurrent-ruby (>= 1.1.10)
csv (>= 3.0.9)
fileutils (>= 1.1.0)
json (>= 2.1.0)
language_server-protocol (>= 3.15, < 4.0)
listen (~> 3.0)
logger (>= 1.3.0)
parser (>= 3.1)
rainbow (>= 2.2.2, < 4.0)
rbs (>= 3.5.0.pre)
securerandom (>= 0.1)
strscan (>= 1.0.0)
terminal-table (>= 2, < 4)
strscan (3.1.0)
terminal-table (3.0.2)
unicode-display_width (>= 1.1.1, < 3)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
unicode-display_width (2.5.0)
uri (0.13.0)
webrick (1.8.1)

Expand All @@ -47,7 +108,9 @@ DEPENDENCIES
fetch-api!
rackup
rake
rbs
rspec
steep
webrick

BUNDLED WITH
Expand Down
10 changes: 10 additions & 0 deletions Steepfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
target :lib do
signature 'sig'

check 'lib'

library 'json'
library 'net-http'
library 'rack'
library 'singleton'
end
2 changes: 1 addition & 1 deletion fetch-api.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
spec.summary = 'Something like the Fetch API for Ruby'
spec.homepage = 'https://github.com/ursm/fetch-api'
spec.license = 'MIT'
spec.required_ruby_version = '>= 3.2.0'
spec.required_ruby_version = '>= 3.1.0'

spec.metadata['homepage_uri'] = spec.homepage
spec.metadata['source_code_uri'] = 'https://github.com/ursm/fetch-api.git'
Expand Down
12 changes: 6 additions & 6 deletions lib/fetch/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def fetch(resource, method: :get, headers: [], body: nil, redirect: :follow, _re
req = Net::HTTP.const_get(method.capitalize).new(uri)

headers.each do |k, v|
req[k] = v
req[k.to_s] = v.to_s
end

case body
Expand All @@ -28,7 +28,7 @@ def fetch(resource, method: :get, headers: [], body: nil, redirect: :follow, _re
if v.is_a?(File)
[k, v, {
filename: File.basename(v.path),
content_type: MiniMime.lookup_by_filename(v.path)&.content_type || 'application/octet-stream'
content_type: MiniMime.lookup_by_filename(v.path)&.content_type || 'application/octet-stream' # steep:ignore UnknownConstant
}]
else
[k, v]
Expand All @@ -40,7 +40,7 @@ def fetch(resource, method: :get, headers: [], body: nil, redirect: :follow, _re
req.body = body
end

http = Net::HTTP.new(uri.hostname, uri.port)
http = Net::HTTP.new(uri.hostname, uri.port) # steep:ignore ArgumentTypeMismatch
http.use_ssl = uri.scheme == 'https'

res = http.start { _1.request(req) }
Expand All @@ -49,7 +49,7 @@ def fetch(resource, method: :get, headers: [], body: nil, redirect: :follow, _re
when Net::HTTPRedirection
case redirect.to_s
when 'follow'
fetch(res['Location'], method:, headers:, body:, redirect:, _redirected: true)
fetch(res['Location'], method:, headers:, body:, redirect:, _redirected: true) # steep:ignore ArgumentTypeMismatch
when 'error'
raise RedirectError, "redirected to #{res['Location']}"
when 'manual'
Expand All @@ -66,9 +66,9 @@ def fetch(resource, method: :get, headers: [], body: nil, redirect: :follow, _re

def to_response(url, res, redirected)
Response.new(
url: ,
url: url.to_str,
status: res.code.to_i,
headers: Headers.new(res),
headers: Headers.new(res.each),
body: res.body,
redirected:
)
Expand Down
14 changes: 5 additions & 9 deletions lib/fetch/form_data.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
require_relative 'symbol_to_str'

module Fetch
class FormData
include Enumerable

using SymbolToStr

def self.build(enumerable)
data = FormData.new

Expand All @@ -23,23 +19,23 @@ def initialize
attr_reader :entries

def append(key, value)
@entries.push [key.to_str, value]
@entries.push [key.to_s, value.is_a?(File) ? value : value.to_s]
end

def delete(key)
@entries.reject! {|k,| k == key.to_str }
@entries.reject! {|k,| k == key.to_s }
end

def get(key)
@entries.assoc(key.to_str)&.last
@entries.assoc(key.to_s)&.last
end

def get_all(key)
@entries.select {|k,| k == key.to_str }.map(&:last)
@entries.select {|k,| k == key.to_s }.map(&:last)
end

def has(key)
@entries.any? {|k,| k == key.to_str }
@entries.any? {|k,| k == key.to_s }
end

def keys
Expand Down
14 changes: 5 additions & 9 deletions lib/fetch/headers.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
require_relative 'symbol_to_str'

module Fetch
class Headers
include Enumerable

using SymbolToStr

def initialize(init = [])
@data = {}

Expand All @@ -15,31 +11,31 @@ def initialize(init = [])
end

def append(key, value)
(@data[key.to_str.downcase] ||= []) << value
(@data[key.to_s.downcase] ||= []) << value.to_s
end

def delete(key)
@data.delete key.to_str.downcase
@data.delete key.to_s.downcase
end

def entries
@data.map {|k, vs| [k, vs.join(', ')] }
end

def get(key)
@data[key.to_str.downcase]&.join(', ')
@data[key.to_s.downcase]&.join(', ')
end

def has(key)
@data.key?(key.to_str.downcase)
@data.key?(key.to_s.downcase)
end

def keys
@data.keys
end

def set(key, value)
@data[key.to_str.downcase] = [value]
@data[key.to_s.downcase] = [value]
end

def values
Expand Down
16 changes: 14 additions & 2 deletions lib/fetch/response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,17 @@
require 'rack/utils'

module Fetch
Response = Data.define(:url, :status, :headers, :body, :redirected) {
class Response
def initialize(url:, status:, headers:, body:, redirected:)
@url = url
@status = status
@headers = headers
@body = body
@redirected = redirected
end

attr_reader :url, :status, :headers, :body, :redirected

def ok
status.between?(200, 299)
end
Expand All @@ -12,7 +22,9 @@ def status_text
end

def json(...)
return nil unless body

JSON.parse(body, ...)
end
}
end
end
9 changes: 0 additions & 9 deletions lib/fetch/symbol_to_str.rb

This file was deleted.

Loading