Skip to content

Commit

Permalink
Decouple scanning_gemfile from find_gem_files and refactor its implem…
Browse files Browse the repository at this point in the history
…entation

- Modified the scanning_gemfile method to be independent from the find_gem_files method, changing its invocation from a direct method call to being called from a delegation block.
- Changed the scanning_gemfile method to accept the path to the Gemfile as an argument, removing the dependency on Ocran.gemfile.
- Updated the return value of the scanning_gemfile method to be an array of specs, which are now composed within a delegation block.
  • Loading branch information
shinokaro committed Jun 22, 2024
1 parent f5167bb commit f6c155c
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions bin/ocran
Original file line number Diff line number Diff line change
Expand Up @@ -368,11 +368,11 @@ EOF
include
end

def Ocran.scanning_gemfile
gems = {}
def Ocran.scanning_gemfile(gemfile_path)
gems = []

# If a Bundler Gemfile was provided, add all gems it specifies
if Ocran.gemfile
begin # Preserve indentation to avoid corrupting information used by `git blame`.
Ocran.msg "Scanning Gemfile"
# Load Rubygems and Bundler so we can scan the Gemfile
["rubygems", "bundler"].each do |lib|
Expand All @@ -383,10 +383,10 @@ EOF
end
end

ENV["BUNDLE_GEMFILE"] = Ocran.gemfile.to_s
ENV["BUNDLE_GEMFILE"] = gemfile_path.to_s
Bundler.load.specs.each do |spec|
Ocran.verbose_msg "From Gemfile, adding gem #{spec.full_name}"
gems[spec.name] ||= spec
gems << spec
end

# Since Ruby 3.0 and later, the minimum version of Bundler is 2.0.0,
Expand All @@ -405,7 +405,7 @@ EOF
def self.find_gem_files(features)
gem_files = []
features_from_gems = []
gems = Ocran.scanning_gemfile
gems = {}

if defined?(Gem)
require_relative "../lib/ocran/gem_spec_queryable"
Expand Down Expand Up @@ -515,10 +515,19 @@ EOF
require_relative "../lib/ocran/host_config_helper"
Ocran.extend HostConfigHelper

# If a Bundler Gemfile was provided, add all gems it specifies
gemfile_specs = if Ocran.gemfile
Ocran.scanning_gemfile(Ocran.gemfile)
else
[]
end

# Find gems files and remove them from features
gem_files, features_from_gems, gemspecs = find_gem_files(features)
gem_files, features_from_gems, loaded_specs = find_gem_files(features)
features -= features_from_gems

gemspecs = (gemfile_specs + loaded_specs).uniq { |spec| spec.name }

# Include encoding support files
if Ocran.enc
all_load_paths.each do |path|
Expand Down

0 comments on commit f6c155c

Please sign in to comment.