Skip to content

Commit

Permalink
Remove unnecessary Gem constant check in find_gem_files
Browse files Browse the repository at this point in the history
- Eliminated the conditional check for the Gem constant within the find_gem_files method, as the method does not depend on this constant.
  • Loading branch information
shinokaro committed Jun 25, 2024
1 parent d3759d2 commit 22ee06a
Showing 1 changed file with 35 additions and 37 deletions.
72 changes: 35 additions & 37 deletions bin/ocran
Original file line number Diff line number Diff line change
Expand Up @@ -433,46 +433,44 @@ EOF
def self.find_gem_files(features_from_gems, loaded_specs)
gem_files = []

if defined?(Gem)
loaded_specs.each do |spec|
# In an environment executed from `bundle exec`, `bundler`'s `spec.gem_dir`
# returns a path that does not exist.
unless File.directory?(spec.gem_dir)
Ocran.warn "Gem #{spec.full_name} root folder was not found, skipping"
next
end
loaded_specs.each do |spec|
# In an environment executed from `bundle exec`, `bundler`'s `spec.gem_dir`
# returns a path that does not exist.
unless File.directory?(spec.gem_dir)
Ocran.warn "Gem #{spec.full_name} root folder was not found, skipping"
next
end

# Determine which set of files to include for this particular gem
include = Ocran.gem_inclusion_set(spec.name)
Ocran.msg "Detected gem #{spec.full_name} (#{include.join(", ")})"

gem_root = Pathname(spec.gem_dir)

require_relative "../lib/ocran/gem_spec_queryable"
spec.extend(GemSpecQueryable)

actual_files = include.map do |set|
case set
when :spec
spec.files.map { |file| Pathname(file) }
when :loaded
features_from_gems.select { |feature| feature.subpath?(gem_root) }
when :files
spec.resource_files
when :extras
spec.extra_files
when :scripts
spec.script_files
else
raise "Invalid file set: #{set}. Please specify a valid file set (:spec, :loaded, :files, :extras, :scripts)."
end
end.flatten
Ocran.msg "\t#{actual_files.size} files, #{actual_files.sum(0, &:size)} bytes"
# Determine which set of files to include for this particular gem
include = Ocran.gem_inclusion_set(spec.name)
Ocran.msg "Detected gem #{spec.full_name} (#{include.join(", ")})"

gem_root = Pathname(spec.gem_dir)

require_relative "../lib/ocran/gem_spec_queryable"
spec.extend(GemSpecQueryable)

actual_files = include.map do |set|
case set
when :spec
spec.files.map { |file| Pathname(file) }
when :loaded
features_from_gems.select { |feature| feature.subpath?(gem_root) }
when :files
spec.resource_files
when :extras
spec.extra_files
when :scripts
spec.script_files
else
raise "Invalid file set: #{set}. Please specify a valid file set (:spec, :loaded, :files, :extras, :scripts)."
end
end.flatten
Ocran.msg "\t#{actual_files.size} files, #{actual_files.sum(0, &:size)} bytes"

gem_files += actual_files
end
gem_files.uniq!
gem_files += actual_files
end
gem_files.uniq!

gem_files
end
Expand Down

0 comments on commit 22ee06a

Please sign in to comment.