Skip to content

Commit a33cdaf

Browse files
committed
fix: use keyword arguments for DefaultCmabClient to resolve Rubocop linting error
- Changed initialize method to use keyword arguments instead of positional arguments - Updated all call sites to use keyword arguments - Fixes Metrics/ParameterLists offense (too many optional parameters) - All tests passing (11 examples, 0 failures)
1 parent 3a7b54d commit a33cdaf

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

lib/optimizely.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,9 @@ def initialize(
137137
# Initialize CMAB components if cmab service is nil
138138
if cmab_service.nil?
139139
@cmab_client = DefaultCmabClient.new(
140-
nil,
141-
CmabRetryConfig.new,
142-
@logger
140+
http_client: nil,
141+
retry_config: CmabRetryConfig.new,
142+
logger: @logger
143143
)
144144
@cmab_cache = LRUCache.new(Optimizely::DefaultCmabCacheOptions::DEFAULT_CMAB_CACHE_SIZE, Optimizely::DefaultCmabCacheOptions::DEFAULT_CMAB_CACHE_TIMEOUT)
145145
@cmab_service = DefaultCmabService.new(

lib/optimizely/cmab/cmab_client.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class DefaultCmabClient
4343
# Client for interacting with the CMAB service.
4444
# Provides methods to fetch decisions with optional retry logic.
4545

46-
def initialize(http_client = nil, retry_config = nil, logger = nil, prediction_endpoint = nil)
46+
def initialize(http_client: nil, retry_config: nil, logger: nil, prediction_endpoint: nil)
4747
# Initialize the CMAB client.
4848
# Args:
4949
# http_client: HTTP client for making requests.

spec/cmab/cmab_client_spec.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
end
5656

5757
context 'when client is configured without retries' do
58-
let(:client) { described_class.new(nil, Optimizely::CmabRetryConfig.new(max_retries: 0), spy_logger) }
58+
let(:client) { described_class.new(http_client: nil, retry_config: Optimizely::CmabRetryConfig.new(max_retries: 0), logger: spy_logger) }
5959

6060
it 'should return the variation id on success' do
6161
WebMock.stub_request(:post, expected_url)
@@ -132,7 +132,7 @@
132132
end
133133

134134
context 'when client is configured with retries' do
135-
let(:client_with_retry) { described_class.new(nil, retry_config, spy_logger) }
135+
let(:client_with_retry) { described_class.new(http_client: nil, retry_config: retry_config, logger: spy_logger) }
136136

137137
it 'should return the variation id on first try' do
138138
WebMock.stub_request(:post, expected_url)
@@ -199,7 +199,7 @@
199199
context 'when custom prediction endpoint is configured' do
200200
let(:custom_endpoint) { 'https://custom.endpoint.com/predict/%s' }
201201
let(:custom_url) { 'https://custom.endpoint.com/predict/test_rule' }
202-
let(:client_with_custom_endpoint) { described_class.new(nil, Optimizely::CmabRetryConfig.new(max_retries: 0), spy_logger, custom_endpoint) }
202+
let(:client_with_custom_endpoint) { described_class.new(http_client: nil, retry_config: Optimizely::CmabRetryConfig.new(max_retries: 0), logger: spy_logger, prediction_endpoint: custom_endpoint) }
203203

204204
it 'should use the custom prediction endpoint' do
205205
WebMock.stub_request(:post, custom_url)
@@ -215,7 +215,7 @@
215215
end
216216

217217
context 'when no prediction endpoint is provided' do
218-
let(:client_with_default) { described_class.new(nil, Optimizely::CmabRetryConfig.new(max_retries: 0), spy_logger, nil) }
218+
let(:client_with_default) { described_class.new(http_client: nil, retry_config: Optimizely::CmabRetryConfig.new(max_retries: 0), logger: spy_logger, prediction_endpoint: nil) }
219219

220220
it 'should use the default prediction endpoint' do
221221
WebMock.stub_request(:post, expected_url)
@@ -231,7 +231,7 @@
231231
end
232232

233233
context 'when empty string prediction endpoint is provided' do
234-
let(:client_with_empty_endpoint) { described_class.new(nil, Optimizely::CmabRetryConfig.new(max_retries: 0), spy_logger, '') }
234+
let(:client_with_empty_endpoint) { described_class.new(http_client: nil, retry_config: Optimizely::CmabRetryConfig.new(max_retries: 0), logger: spy_logger, prediction_endpoint: '') }
235235

236236
it 'should fall back to the default prediction endpoint' do
237237
WebMock.stub_request(:post, expected_url)

0 commit comments

Comments
 (0)