Skip to content
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
7 changes: 5 additions & 2 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@ Metrics/ParameterLists:
Metrics/PerceivedComplexity:
Enabled: false

# Need to preserve block identifier for documentation.
Naming/BlockForwarding:
Exclude:
- "**/*.rbi"
Enabled: false

Naming/ClassAndModuleCamelCase:
Exclude:
Expand Down Expand Up @@ -153,6 +153,9 @@ Style/Alias:
Style/AndOr:
EnforcedStyle: always

Style/ArgumentsForwarding:
Enabled: false

Style/BisectedAttrAccessor:
Exclude:
- "**/*.rbi"
Expand Down
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ xargs = %w[xargs --no-run-if-empty --null --max-procs=0 --max-args=300 --]
multitask(default: [:test])

multitask(:test) do
rb =
rb =
FileList[ENV.fetch("TEST", "./test/**/*_test.rb")]
.map { "require_relative(#{_1.dump});" }
.join
Expand Down
2 changes: 1 addition & 1 deletion Steepfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ target :lib do

YAML.safe_load_file("./manifest.yaml", symbolize_names: true) => { dependencies: }
# currently these libraries lack the `*.rbs` annotations required by `steep`
stdlibs = dependencies - %w[etc net/http rbconfig set stringio]
stdlibs = dependencies - %w[English etc net/http rbconfig set stringio]

stdlibs.each { library(_1) }
end
31 changes: 16 additions & 15 deletions lib/lithic.rb
Original file line number Diff line number Diff line change
@@ -1,21 +1,7 @@
# frozen_string_literal: true

# We already ship the preferred sorbet manifests in the package itself.
# `tapioca` currently does not offer us a way to opt out of unnecessary compilation.
if Object.const_defined?(:Tapioca) && caller.chain([$0]).chain(ARGV).grep(/tapioca/)
Warning.warn(
<<~WARN
\n
⚠️ skipped loading of "lithic" gem under `tapioca`.

This message is normal and expected if you are running a `tapioca` command, and does not impact `.rbi` generation.
\n
WARN
)
return
end

# Standard libraries.
require "English"
require "cgi"
require "date"
require "erb"
Expand All @@ -30,6 +16,21 @@
require "time"
require "uri"

# We already ship the preferred sorbet manifests in the package itself.
# `tapioca` currently does not offer us a way to opt out of unnecessary compilation.
if Object.const_defined?(:Tapioca) && caller.chain([$PROGRAM_NAME]).chain(ARGV).grep(/tapioca/)
Warning.warn(
<<~WARN
\n
⚠️ skipped loading of "lithic" gem under `tapioca`.

This message is normal and expected if you are running a `tapioca` command, and does not impact `.rbi` generation.
\n
WARN
)
return
end

# Gems.
require "connection_pool"

Expand Down
8 changes: 4 additions & 4 deletions lib/lithic/transport/pooled_net_requester.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def calibrate_socket_timeout(conn, deadline)
#
# @yieldparam [String]
# @return [Net::HTTPGenericRequest]
def build_request(request, &)
def build_request(request, &blk)
method, url, headers, body = request.fetch_values(:method, :url, :headers, :body)
req = Net::HTTPGenericRequest.new(
method.to_s.upcase,
Expand All @@ -70,13 +70,13 @@ def build_request(request, &)
nil
in String
req["content-length"] ||= body.bytesize.to_s unless req["transfer-encoding"]
req.body_stream = Lithic::Util::ReadIOAdapter.new(body, &)
req.body_stream = Lithic::Util::ReadIOAdapter.new(body, &blk)
in StringIO
req["content-length"] ||= body.size.to_s unless req["transfer-encoding"]
req.body_stream = Lithic::Util::ReadIOAdapter.new(body, &)
req.body_stream = Lithic::Util::ReadIOAdapter.new(body, &blk)
in IO | Enumerator
req["transfer-encoding"] ||= "chunked" unless req["content-length"]
req.body_stream = Lithic::Util::ReadIOAdapter.new(body, &)
req.body_stream = Lithic::Util::ReadIOAdapter.new(body, &blk)
end

req
Expand Down
4 changes: 3 additions & 1 deletion lib/lithic/type/array_of.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ def ===(other) = other.is_a?(Array) && other.all?(item_type)
# @param other [Object]
#
# @return [Boolean]
def ==(other) = other.is_a?(Lithic::ArrayOf) && other.nilable? == nilable? && other.item_type == item_type
def ==(other)
other.is_a?(Lithic::ArrayOf) && other.nilable? == nilable? && other.item_type == item_type
end

# @api private
#
Expand Down
8 changes: 5 additions & 3 deletions lib/lithic/type/base_model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ def fields
end
rescue StandardError
cls = self.class.name.split("::").last
# rubocop:disable Layout/LineLength
message = "Failed to parse #{cls}.#{__method__} from #{value.class} to #{target.inspect}. To get the unparsed API response, use #{cls}[:#{__method__}]."
# rubocop:enable Layout/LineLength
raise Lithic::ConversionError.new(message)
end
end
Expand Down Expand Up @@ -205,14 +207,13 @@ def coerce(value, state:)
instance = new
data = instance.to_h

# rubocop:disable Metrics/BlockLength
fields.each do |name, field|
mode, required, target = field.fetch_values(:mode, :required, :type)
api_name, nilable, const = field.fetch_values(:api_name, :nilable, :const)

unless val.key?(api_name)
if const != Lithic::Util::OMIT
exactness[:yes] += 1
elsif required && mode != :dump
if required && mode != :dump && const == Lithic::Util::OMIT
exactness[nilable ? :maybe : :no] += 1
else
exactness[:yes] += 1
Expand All @@ -238,6 +239,7 @@ def coerce(value, state:)
end
data.store(name, converted)
end
# rubocop:enable Metrics/BlockLength

keys.each { data.store(_1, val.fetch(_1)) }
instance
Expand Down
2 changes: 1 addition & 1 deletion lib/lithic/type/base_page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def next_page = (raise NotImplementedError)
# @param blk [Proc]
#
# @return [void]
def auto_paging_each(&) = (raise NotImplementedError)
def auto_paging_each(&blk) = (raise NotImplementedError)

# @return [Enumerable]
def to_enum = super(:auto_paging_each)
Expand Down
4 changes: 3 additions & 1 deletion lib/lithic/type/hash_of.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ def ===(other)
# @param other [Object]
#
# @return [Boolean]
def ==(other) = other.is_a?(Lithic::HashOf) && other.nilable? == nilable? && other.item_type == item_type
def ==(other)
other.is_a?(Lithic::HashOf) && other.nilable? == nilable? && other.item_type == item_type
end

# @api private
#
Expand Down
2 changes: 2 additions & 0 deletions lib/lithic/type/union.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@ def ===(other)
#
# @return [Boolean]
def ==(other)
# rubocop:disable Layout/LineLength
other.is_a?(Module) && other.singleton_class <= Lithic::Union && other.derefed_variants == derefed_variants
# rubocop:enable Layout/LineLength
end

# @api private
Expand Down
1 change: 1 addition & 0 deletions manifest.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
dependencies:
- English
- cgi
- date
- erb
Expand Down