Skip to content

Commit

Permalink
Refactor extract_gem_files method for clarity and efficiency
Browse files Browse the repository at this point in the history
- Replaced the each loop in feature_from_gems with filter_map for streamlined value generation.
- Changed the conditional check from gems.find to gems.any? to improve performance.
- Consolidated separate if statements into a single if-elsif chain, removing unnecessary next statements.
  • Loading branch information
shinokaro committed Jun 26, 2024
1 parent e70391b commit 3df6855
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions bin/ocran
Original file line number Diff line number Diff line change
Expand Up @@ -392,20 +392,17 @@ EOF

def self.extract_gem_files(features)
require_relative "../lib/ocran/gem_spec_queryable"
features_from_gems = []
gems = {}

# Fall back to gem detection (loaded_specs are not population on
# all Ruby versions)
features.each do |feature|
features_from_gems = features.filter_map do |feature|
# Skip if found in known Gem dir
if gems.find { |_gem, spec| feature.subpath?(spec.gem_dir) }
features_from_gems << feature
next
end
if (spec = GemSpecQueryable.find_spec(feature))
if gems.any? { |_name, spec| feature.subpath?(spec.gem_dir) }
feature
elsif (spec = GemSpecQueryable.find_spec(feature))
gems[spec.name] ||= spec
features_from_gems << feature
feature
else
Ocran.warn "Failed to load gemspec for #{feature}"
end
Expand Down

0 comments on commit 3df6855

Please sign in to comment.