Skip to content

Commit

Permalink
Change base to keyword argument
Browse files Browse the repository at this point in the history
  • Loading branch information
TonyCTHsu committed Feb 2, 2023
1 parent 779117e commit 6ec95b9
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 14 deletions.
4 changes: 2 additions & 2 deletions lib/datadog/tracing/distributed/b3_single.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ def extract(env)
return unless value

parts = value.split('-')
trace_id = Helpers.value_to_id(parts[0], 16) unless parts.empty?
span_id = Helpers.value_to_id(parts[1], 16) if parts.length > 1
trace_id = Helpers.value_to_id(parts[0], base: 16) unless parts.empty?
span_id = Helpers.value_to_id(parts[1], base: 16) if parts.length > 1
sampling_priority = Helpers.value_to_number(parts[2]) if parts.length > 2

# Return if this propagation is not valid
Expand Down
4 changes: 2 additions & 2 deletions lib/datadog/tracing/distributed/fetcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ def [](key)
end

def id(key, base: 10)
Helpers.value_to_id(self[key], base)
Helpers.value_to_id(self[key], base: base)
end

def number(key, base: 10)
Helpers.value_to_number(self[key], base)
Helpers.value_to_number(self[key], base: base)
end
end
end
Expand Down
8 changes: 3 additions & 5 deletions lib/datadog/tracing/distributed/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,8 @@ def self.truncate_base16_number(value)
value.sub(/^0*(?=(0$)|[^0])/, '')
end

# DEV: move `base` to a keyword argument
def self.value_to_id(value, base = 10)
id = value_to_number(value, base)
def self.value_to_id(value, base: 10)
id = value_to_number(value, base: base)

# Return early if we could not parse a number
return if id.nil?
Expand All @@ -53,8 +52,7 @@ def self.value_to_id(value, base = 10)
id < 0 ? id + (2**64) : id
end

# DEV: move `base` to a keyword argument
def self.value_to_number(value, base = 10)
def self.value_to_number(value, base: 10)
# It's important to make a difference between no data and zero.
return if value.nil?

Expand Down
4 changes: 2 additions & 2 deletions spec/datadog/tracing/distributed/fetcher_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

it 'delegates to Datadog::Tracing::Distributed::Helpers.value_to_id' do
ret = double('return')
expect(Datadog::Tracing::Distributed::Helpers).to receive(:value_to_id).with(value, base).and_return(ret)
expect(Datadog::Tracing::Distributed::Helpers).to receive(:value_to_id).with(value, base: base).and_return(ret)
is_expected.to eq(ret)
end
end
Expand All @@ -48,7 +48,7 @@

it 'delegates to Datadog::Tracing::Distributed::Helpers.value_to_number' do
ret = double('return')
expect(Datadog::Tracing::Distributed::Helpers).to receive(:value_to_number).with(value, base).and_return(ret)
expect(Datadog::Tracing::Distributed::Helpers).to receive(:value_to_number).with(value, base: base).and_return(ret)
is_expected.to eq(ret)
end
end
Expand Down
6 changes: 3 additions & 3 deletions spec/datadog/tracing/distributed/helpers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@
['10000', 65536],
['deadbeef', 3735928559],
].each do |value, expected|
xcontext value.inspect do
it { expect(described_class.value_to_id(value, 16)).to eq(expected) }
context value.inspect do
it { expect(described_class.value_to_id(value, base: 16)).to eq(expected) }
end
end
end
Expand Down Expand Up @@ -170,7 +170,7 @@
['invalid-base16', nil]
].each do |value, expected|
context value.inspect do
subject(:subject) { described_class.value_to_number(value, 16) }
subject(:subject) { described_class.value_to_number(value, base: 16) }

it { is_expected.to be == expected }
end
Expand Down

0 comments on commit 6ec95b9

Please sign in to comment.