Skip to content

Commit

Permalink
Add rbs and touch up public methods (#157)
Browse files Browse the repository at this point in the history
  • Loading branch information
mullermp authored Aug 21, 2023
1 parent d692df2 commit c77423a
Show file tree
Hide file tree
Showing 81 changed files with 759 additions and 287 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion codegen/projections/rails_json/lib/rails_json/client.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion codegen/projections/weather/lib/weather/client.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion codegen/projections/white_label/lib/white_label/client.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions codegen/projections/white_label/spec/interceptor_spec.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def read_before_execution(context); end
client = Client.new(config)

expect(interceptor).to receive(hook)
.with(instance_of(Hearth::InterceptorContext))
.with(instance_of(Hearth::Interceptor::Context))

client.kitchen_sink
end
Expand All @@ -38,7 +38,7 @@ def read_before_execution(context); end
client = Client.new(config)

expect(interceptor).to receive(hook)
.with(instance_of(Hearth::InterceptorContext))
.with(instance_of(Hearth::Interceptor::Context))

client.kitchen_sink({}, interceptors: [interceptor])
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public final class Hearth {
.build();

public static final Symbol STUBS = Symbol.builder()
.namespace("Hearth::Stubbing", "::")
.namespace("Hearth", "::")
.name("Stubs")
.build();

Expand Down
5 changes: 1 addition & 4 deletions hearth/Steepfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@

D = Steep::Diagnostic

target :app do
target :lib do
signature 'sig'

check 'lib/hearth/structure'
check 'lib/hearth/union'

configure_code_diagnostics(D::Ruby.strict)
end
5 changes: 2 additions & 3 deletions hearth/lib/hearth.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

require_relative 'hearth/block_io'
require_relative 'hearth/checksums'
require_relative 'hearth/client_stubs'
require_relative 'hearth/configuration'
require_relative 'hearth/config/env_provider'
require_relative 'hearth/config/resolver'
Expand All @@ -24,7 +25,6 @@
require_relative 'hearth/http'
require_relative 'hearth/identity_resolver'
require_relative 'hearth/interceptor'
require_relative 'hearth/interceptor_context'
require_relative 'hearth/interceptor_list'
require_relative 'hearth/json'
require_relative 'hearth/plugin_list'
Expand All @@ -38,8 +38,7 @@
require_relative 'hearth/retry'
require_relative 'hearth/signers'
require_relative 'hearth/structure'
require_relative 'hearth/stubbing/client_stubs'
require_relative 'hearth/stubbing/stubs'
require_relative 'hearth/stubs'
require_relative 'hearth/time_helper'
require_relative 'hearth/union'
require_relative 'hearth/validator'
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion hearth/lib/hearth/config/env_provider.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# frozen_string_literal: true

module Hearth
# @api private
module Config
# Parses and validates values provided in ENV
# @api private
class EnvProvider
def initialize(env_key, type: 'String')
@env_key = env_key
Expand Down
3 changes: 2 additions & 1 deletion hearth/lib/hearth/config/resolver.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# frozen_string_literal: true

module Hearth
# @api private
module Config
# @api private
# Resolves configuration options.
class Resolver
private_class_method :new

Expand Down
1 change: 1 addition & 0 deletions hearth/lib/hearth/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

module Hearth
# A module mixed into Config structs that resolves default value providers.
# @api private
module Configuration
def initialize(**options)
Hearth::Validator.validate_unknown!(self, options, context: 'config')
Expand Down
2 changes: 1 addition & 1 deletion hearth/lib/hearth/context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def initialize(options = {})

# @api private
def interceptor_context(input, output)
Hearth::InterceptorContext.new(
Hearth::Interceptor::Context.new(
input: input,
request: request,
response: response,
Expand Down
2 changes: 2 additions & 0 deletions hearth/lib/hearth/dns.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# Ruby DNS resolution, which may be Resolv or the system resolver.

# Patch IPSocket
# @api private
class << IPSocket
alias original_hearth_getaddress getaddress

Expand All @@ -30,6 +31,7 @@ def getaddress(host)
end

# Patch TCPSocket
# @api private
class TCPSocket < IPSocket
alias original_hearth_initialize initialize

Expand Down
14 changes: 3 additions & 11 deletions hearth/lib/hearth/http/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Client
#
# @param [Hash] options The options for this HTTP Client
#
# @param options [Logger] (Logger.new($stdout)) :logger A logger
# @option options [Logger] (Logger.new($stdout)) :logger A logger
# used to log Net::HTTP requests and responses when `:debug_output`
# is enabled.
#
Expand Down Expand Up @@ -100,7 +100,7 @@ def initialize(options = {})

# @param [Request] request
# @param [Response] response
# @param [Logger] (nil) logger
# @param [Logger] logger (nil)
# @return [Response]
def transmit(request:, response:, logger: nil)
net_request = build_net_request(request)
Expand Down Expand Up @@ -263,7 +263,7 @@ def pool_config

# Helper methods extended onto Net::HTTP objects.
# @api private
class HTTP < Delegator
class HTTP < SimpleDelegator
def initialize(http)
super(http)
@http = http
Expand All @@ -272,14 +272,6 @@ def initialize(http)
# @return [Integer, nil]
attr_reader :last_used

def __getobj__
@http
end

def __setobj__(obj)
@http = obj
end

# Sends the request and tracks that this connection has been used.
def request(...)
@http.request(...)
Expand Down
1 change: 1 addition & 0 deletions hearth/lib/hearth/interceptor.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# frozen_string_literal: true

require_relative 'interceptor/context'
require_relative 'interceptor/hooks'

module Hearth
Expand Down
36 changes: 36 additions & 0 deletions hearth/lib/hearth/interceptor/context.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# frozen_string_literal: true

module Hearth
module Interceptor
# Context provided to interceptor hook methods.
class Context
# @param [Struct] input
# @param [Hearth::Request] request
# @param [Hearth::Response] response
# @param [Hearth::Output] output
# @param [Hash] attributes ({}) additional interceptor data
def initialize(input:, request:, response:, output:, attributes: {})
@input = input
@request = request
@response = response
@output = output
@attributes = attributes
end

# @return [Struct] Modeled input, i.e. Types::<Operation>Input
attr_reader :input

# @return [Hearth::Request]
attr_reader :request

# @return [Hearth::Response]
attr_reader :response

# @return [Hearth::Output] only available to hooks after transmit
attr_reader :output

# @return [Hash] attributes additional interceptor data
attr_reader :attributes
end
end
end
35 changes: 0 additions & 35 deletions hearth/lib/hearth/interceptor_context.rb

This file was deleted.

2 changes: 1 addition & 1 deletion hearth/lib/hearth/interceptor_list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class InterceptorList

# Initialize an InterceptorList.
#
# @param [Array] ([]) interceptors A list of interceptors.
# @param [Array] interceptors ([]) A list of interceptors.
def initialize(interceptors = [])
unless interceptors.respond_to?(:each)
raise ArgumentError, 'Interceptors must be an enumerable'
Expand Down
2 changes: 1 addition & 1 deletion hearth/lib/hearth/middleware/send.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Send
# that are responsible for creating a stubbed error response. They
# must respond to #stub and take the response and stub data as
# arguments.
# @param [Stubs] stubs A {Hearth::Stubbing:Stubs} object containing
# @param [Stubs] stubs A {Hearth::Stubs} object containing
# stubbed data for any given operation.
def initialize(_app, client:, stub_responses:,
stub_data_class:, stub_error_classes:, stubs:)
Expand Down
2 changes: 1 addition & 1 deletion hearth/lib/hearth/plugin_list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class PluginList

# Initialize a PluginList.
#
# @param [Array] ([]) plugins A list of plugins to initialize with
# @param [Array] plugins ([]) A list of plugins to initialize with
def initialize(plugins = [])
unless plugins.respond_to?(:each)
raise ArgumentError, 'Plugins must be an enumerable'
Expand Down
5 changes: 4 additions & 1 deletion hearth/lib/hearth/refreshing_identity_resolver.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# frozen_string_literal: true

module Hearth
# Resolves an identity from identity properties.
# A module that can be included in a class to provide a #identity method.
# The class must implement #refresh(properties) that sets @identity. The
# refresh method will be called when #identity is called and the identity
# is nil or near expiration.
module RefreshingIdentityResolver
SYNC_EXPIRATION_LENGTH = 300 # 5 minutes
ASYNC_EXPIRATION_LENGTH = 600 # 10 minutes
Expand Down
1 change: 1 addition & 0 deletions hearth/lib/hearth/retry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require_relative 'retry/strategy'

require_relative 'retry/adaptive'
require_relative 'retry/capacity_not_available_error'
require_relative 'retry/client_rate_limiter'
require_relative 'retry/exponential_backoff'
require_relative 'retry/retry_quota'
Expand Down
9 changes: 9 additions & 0 deletions hearth/lib/hearth/retry/capacity_not_available_error.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true

module Hearth
module Retry
# Raised by Retry::Adaptive when the client rate limiter
# doesn't have capacity.
class CapacityNotAvailableError < RuntimeError; end
end
end
3 changes: 0 additions & 3 deletions hearth/lib/hearth/retry/client_rate_limiter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

module Hearth
module Retry
# Raised when ClientRateLimiter doesn't have capacity.
class CapacityNotAvailableError < RuntimeError; end

# @api private
# Used only in 'adaptive' retry mode
class ClientRateLimiter
Expand Down
1 change: 0 additions & 1 deletion hearth/lib/hearth/retry/exponential_backoff.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

module Hearth
module Retry
# @api private
# Computes an exponential backoff delay for a retry attempt.
class ExponentialBackoff
# Max backoff (in seconds)
Expand Down
Loading

0 comments on commit c77423a

Please sign in to comment.