Skip to content

Commit 26f3a7b

Browse files
Update features to use set (#332)
1 parent 6af5fb2 commit 26f3a7b

4 files changed

Lines changed: 18 additions & 8 deletions

File tree

gems/smithy-client/lib/smithy-client/features.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,16 @@ module Client
66
module Features
77
class << self
88
def track(*features, &block)
9-
Thread.current[:smithy_ruby_features] ||= []
10-
Thread.current[:smithy_ruby_features].concat(features)
9+
Thread.current[:smithy_ruby_features] ||= Set.new
10+
added = features.map { |f| Thread.current[:smithy_ruby_features].add?(f) }
1111
block.call
1212
ensure
13-
Thread.current[:smithy_ruby_features].pop(features.size)
13+
features.each_with_index { |f, i| Thread.current[:smithy_ruby_features].delete(f) if added[i] }
1414
end
1515

1616
def tracked
17-
Thread.current[:smithy_ruby_features] || []
17+
Thread.current[:smithy_ruby_features] || Set.new
18+
Thread.current[:smithy_ruby_features].to_a
1819
end
1920
end
2021
end

gems/smithy-client/spec/smithy-client/features_spec.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,17 @@ module Client
5757
end
5858
expect(Features.tracked).to be_empty
5959
end
60+
61+
it 'does not track duplicate features' do
62+
Features.track('A', 'B') do
63+
expect(Features.tracked).to eq(%w[A B])
64+
Features.track('A') do
65+
expect(Features.tracked).to eq(%w[A B])
66+
end
67+
expect(Features.tracked).to eq(%w[A B])
68+
end
69+
expect(Features.tracked).to be_empty
70+
end
6071
end
6172
end
6273
end

projections/shapes/lib/shapes/client.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,7 @@ class Client < Smithy::Client::Base
161161
# @option options [Boolean] :stub_responses
162162
# When `true`, the client will return stubbed responses instead of networking requests.
163163
# By default fake responses are generated and returned. You can specify the response data
164-
# to return or errors to raise by calling {Stubs#stub_responses}.
165-
# @see Stubs
164+
# to return or errors to raise by calling {Smithy::Client::Stubs#stub_responses}.
166165
# @option options [String] :user_agent_suffix
167166
# An optional string that is appended to the User-Agent header.
168167
# The default User-Agent includes the smithy-client version,

projections/weather/lib/weather/client.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,7 @@ class Client < Smithy::Client::Base
161161
# @option options [Boolean] :stub_responses
162162
# When `true`, the client will return stubbed responses instead of networking requests.
163163
# By default fake responses are generated and returned. You can specify the response data
164-
# to return or errors to raise by calling {Stubs#stub_responses}.
165-
# @see Stubs
164+
# to return or errors to raise by calling {Smithy::Client::Stubs#stub_responses}.
166165
# @option options [String] :user_agent_suffix
167166
# An optional string that is appended to the User-Agent header.
168167
# The default User-Agent includes the smithy-client version,

0 commit comments

Comments
 (0)