Skip to content

Commit ed971ef

Browse files
committed
style: fix RuboCop offenses in CLI code
Use idiomatic Ruby patterns to satisfy linter: - Replace each+append with map for building arrays - Use annotated format tokens (%<name>s) over positional ones - Use %r{} for regex containing slashes
1 parent a98c314 commit ed971ef

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

lib/classifier/cli.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -397,22 +397,22 @@ def list_local_models
397397
return
398398
end
399399

400-
models = [] #: Array[{name: String, registry: String?, path: String}]
401-
402400
# Find models from default registry
403-
Dir.glob(File.join(models_dir, '*.json')).each do |path|
404-
models << { name: File.basename(path, '.json'), registry: nil, path: path }
401+
default_models = Dir.glob(File.join(models_dir, '*.json')).map do |path|
402+
{ name: File.basename(path, '.json'), registry: nil, path: path }
405403
end
406404

407405
# Find models from custom registries (@user/repo structure)
408-
Dir.glob(File.join(models_dir, '@*', '*', '*.json')).each do |path|
406+
custom_models = Dir.glob(File.join(models_dir, '@*', '*', '*.json')).map do |path|
409407
# Extract registry from path: .../models/@user/repo/model.json
410408
repo_dir = File.dirname(path)
411409
user_dir = File.dirname(repo_dir)
412410
registry = "#{File.basename(user_dir).delete_prefix('@')}/#{File.basename(repo_dir)}"
413-
models << { name: File.basename(path, '.json'), registry: registry, path: path }
411+
{ name: File.basename(path, '.json'), registry: registry, path: path }
414412
end
415413

414+
models = default_models + custom_models #: Array[{name: String, registry: String?, path: String}]
415+
416416
if models.empty?
417417
@output << 'No local models found'
418418
return
@@ -443,7 +443,7 @@ def human_size(bytes)
443443
unit_index += 1
444444
end
445445

446-
format('%.1f %s', size, units[unit_index])
446+
format('%<size>.1f %<unit>s', size: size, unit: units[unit_index])
447447
end
448448

449449
def command_pull

test/cli/registry_commands_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def test_models_local_lists_models_from_custom_registries
131131
result = run_cli('models', '--local')
132132

133133
assert_equal 0, result[:exit_code]
134-
assert_match(/@someone\/models:custom-model/, result[:output])
134+
assert_match(%r{@someone/models:custom-model}, result[:output])
135135
end
136136

137137
def test_models_local_shows_no_models_when_cache_empty

0 commit comments

Comments
 (0)