-
Notifications
You must be signed in to change notification settings - Fork 552
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
Extract configurations into separate object #939
Extract configurations into separate object #939
Conversation
lib/stripe.rb
Outdated
# User configurable options | ||
def_delegators :@configuration, :api_key, :api_key= | ||
def_delegators :@configuration, :api_version, :api_version= | ||
def_delegators :@configuration, :stripe_account, :stripe_account= | ||
def_delegators :@configuration, :api_base, :api_base= | ||
def_delegators :@configuration, :uploads_base, :uploads_base= | ||
def_delegators :@configuration, :connect_base, :connect_base= | ||
def_delegators :@configuration, :open_timeout, :open_timeout= | ||
def_delegators :@configuration, :read_timeout, :read_timeout= | ||
def_delegators :@configuration, :proxy, :proxy= | ||
def_delegators :@configuration, :verify_ssl_certs, :verify_ssl_certs= | ||
def_delegators :@configuration, :ca_bundle_path, :ca_bundle_path= | ||
def_delegators :@configuration, :log_level, :log_level= | ||
def_delegators :@configuration, :logger, :logger= | ||
def_delegators :@configuration, :max_network_retries, :max_network_retries= | ||
def_delegators :@configuration, :enable_telemetry=, :enable_telemetry? | ||
|
||
# Internal configuarations | ||
def_delegators :@configuration, :max_network_retry_delay | ||
def_delegators :@configuration, :initial_network_retry_delay | ||
def_delegators :@configuration, :ca_store |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this blob is too large, I can always break them down into relevant groupings like they were previously.
def reverse_duplicate_merge(hash) | ||
dup.tap do |instance| | ||
hash.each do |option, value| | ||
instance.public_send("#{option}=", value) | ||
end | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is what I intend to use in #921 for the client configuration.
I went back and forth on whether or not the duplicate configuration object should be a snapshot or a pointer with overrides (e.g. any options not set would continually point to the global config object in the event those change). However, I feel like that could lead to unexpected behavior, which is why I favored a snapshot.
assert_equal "path/to/ca/bundle", Stripe.ca_bundle_path | ||
ensure | ||
Stripe.ca_bundle_path = old | ||
context "forwardable configurations" do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These specs are slightly redundant, but they're cheap and lock in the expected API on Stripe
for configuration.
@read_timeout = 80 | ||
|
||
@enable_telemetry = true | ||
@configuration = Stripe::StripeConfiguration.setup |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could probably expose this if there's ever a desire to permit something like:
Stripe.configure do |config|
# config.read_timeout = 100
end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point! Let's expose it separately if we decided to do so, but I think this configuration style would be much more "Ruby-ish" than what the gem currently offers.
518b82b
to
3b08dfa
Compare
# map to the same values as the standard library's logger | ||
LEVEL_DEBUG = Logger::DEBUG | ||
LEVEL_ERROR = Logger::ERROR | ||
LEVEL_INFO = Logger::INFO |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left the CA and LEVEL constants here in case folks reference them from outside the gem.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call.
73bb2c7
to
6924f85
Compare
@brandur-stripe wasn't sure what you envisioned the configuration options looking like for #921, but figured I'd take a stab at refactoring it. This should make it fairly easy to pass a configuration object around while defaulting to the global configuration. Happy to explore other routes as well if this doesn't sit well. |
lib/stripe.rb
Outdated
def_delegators :@configuration, :max_network_retries, :max_network_retries= | ||
def_delegators :@configuration, :enable_telemetry=, :enable_telemetry? | ||
|
||
# Internal configuarations |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tiny typo here: "configurations"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoops! I really need to configure my editor to spell check comments 😅
@joeltaylor Wow, there's been a very concerning pattern on my side where you pitch awesome PRs over and it takes me forever to get back to you. Sorry about that! Found a minor typo, but this looks great to me. I'm going to solicit feedback internally in case there is any, but will time out in a day or so. This looks good to merge. |
@brandur-stripe No worries at all – I appreciate you taking the time to review the PR! Once it's all squared away I can plug it into the other PR. |
Adds a `Stripe::StripeConfiguration` object to manage internal and user supplied configuration options. This is primarily motivated by stripe#921 in order to provide a way to set options on for an instance of `StripeClient`.
6924f85
to
174935e
Compare
That would be amazing Joel :) I had a colleague look at this as well, and then liked it too. Thanks again! |
Pushed as 5.24.0. |
Thanks @brandur-stripe! I'll ping you once I integrate this into the other PR. |
Roger that! TY. |
Adds a
Stripe::StripeConfiguration
object to manage internal and user supplied configuration options.This is primarily motivated by discussion in #921 in order to provide a way to set options for an instance of
StripeClient
.