Skip to content

Commit

Permalink
Cleanup more Ruby 2.0 support code
Browse files Browse the repository at this point in the history
Hello I'm Ivo and I'm the world's # 1 fan of keyword arguments.
  • Loading branch information
ivoanjo committed May 19, 2021
1 parent 8434b6c commit 4a48988
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 24 deletions.
27 changes: 8 additions & 19 deletions lib/ddtrace/configuration/agent_settings_resolver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,12 @@ class AgentSettingsResolver
:deprecated_for_removal_transport_configuration_options
) do
def initialize(
# Hacky required kw args, we can get rid of this when we drop Ruby 2.0
ssl: raise(ArgumentError, 'missing keyword :ssl'),
hostname: raise(ArgumentError, 'missing keyword :hostname'),
port: raise(ArgumentError, 'missing keyword :port'),
timeout_seconds: raise(ArgumentError, 'missing keyword :timeout_seconds'),
deprecated_for_removal_transport_configuration_proc: \
raise(ArgumentError, 'missing keyword :deprecated_for_removal_transport_configuration_proc'),
deprecated_for_removal_transport_configuration_options: \
raise(ArgumentError, 'missing keyword :deprecated_for_removal_transport_configuration_options')
ssl:,
hostname:,
port:,
timeout_seconds:,
deprecated_for_removal_transport_configuration_proc:,
deprecated_for_removal_transport_configuration_options:
)
super(ssl, hostname, port, timeout_seconds, deprecated_for_removal_transport_configuration_proc, \
deprecated_for_removal_transport_configuration_options)
Expand Down Expand Up @@ -179,11 +176,7 @@ def unparsed_url_from_env
@unparsed_url_from_env ||= ENV[Datadog::Ext::Transport::HTTP::ENV_DEFAULT_URL]
end

def pick_from(
# Hacky required kw args, we can get rid of this when we drop Ruby 2.0
configurations_in_priority_order: raise(ArgumentError, 'missing keyword :configurations'),
or_use_default: raise(ArgumentError, 'missing keyword :or_use_default')
)
def pick_from(configurations_in_priority_order:, or_use_default:)
detected_configurations_in_priority_order = configurations_in_priority_order.select(&:value?)

if detected_configurations_in_priority_order.any?
Expand Down Expand Up @@ -213,11 +206,7 @@ def log_warning(message)
end

DetectedConfiguration = Struct.new(:friendly_name, :value) do
def initialize(
# Hacky required kw args, we can get rid of this when we drop Ruby 2.0
friendly_name: raise(ArgumentError, 'missing keyword :friendly_name'),
value: raise(ArgumentError, 'missing keyword :value')
)
def initialize(friendly_name:, value:)
super(friendly_name, value)
freeze
end
Expand Down
4 changes: 1 addition & 3 deletions spec/ddtrace/contrib/sucker_punch/patcher_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,7 @@ def perform(action = :none, **_)
clazz = Class.new do
include SuckerPunch::Job

def perform(*args, required: nil)
raise ArgumentError if required.nil? # Ruby 2.0 doesn't support `required:`

def perform(*args, required:)
self.class.instance_variable_get(:@recorded) << [args, required]
end
end
Expand Down
3 changes: 1 addition & 2 deletions spec/support/language_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,4 @@ def symbolize_keys
end
end

# Prepend was private in Ruby 2.0
Hash.send(:prepend, LanguageHelpers::HashHelpers)
Hash.prepend(LanguageHelpers::HashHelpers)

0 comments on commit 4a48988

Please sign in to comment.