Skip to content

Commit

Permalink
Extend filtered_gems to do filtering on install conditions as well
Browse files Browse the repository at this point in the history
  • Loading branch information
paracycle committed May 20, 2019
1 parent 59715dd commit c7f6106
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
7 changes: 6 additions & 1 deletion lib/gel/environment.rb
Expand Up @@ -435,7 +435,12 @@ def self.find_executable(exe, gem_name = nil, gem_version = nil)

def self.filtered_gems(gems = self.gemfile.gems)
platforms = GEMFILE_PLATFORMS.map(&:to_s)
gems = gems.reject { |g| g[2][:platforms] && (Array(g[2][:platforms]).map(&:to_s) & platforms).empty? }
gems = gems.reject do |_, _, options|
platform_options = Array(options[:platforms]).map(&:to_s)

next true if platform_options.any? && (platform_options & platforms).empty?
next true unless options.fetch(:install_if, true)
end
gems
end

Expand Down
10 changes: 8 additions & 2 deletions test/lock_activate_test.rb
Expand Up @@ -90,15 +90,21 @@ def test_activate_lockfile_with_path

def test_ignore_gems_excluded_by_gemfile
gemfile_content = <<GEMFILE
gem "rack"
gem "rack", install_if: true
gem "rack-test", platforms: :rbx
gem "hoe", install_if: false
install_if ->{ false } do
gem "atomic"
end
GEMFILE

lockfile = Tempfile.new("")
lockfile.write(<<LOCKFILE)
GEM
remote: https://rubygems.org/
specs:
atomic (1.1.16)
hoe (3.0.0)
rack (2.0.3)
rack-test (0.6.3)
rack (>= 1.0)
Expand All @@ -109,7 +115,7 @@ def test_ignore_gems_excluded_by_gemfile
LOCKFILE
lockfile.close

with_fixture_gems_installed(["rack-test-0.6.3.gem", "rack-2.0.3.gem", "hoe-3.0.0.gem"]) do |store|
with_fixture_gems_installed(["rack-test-0.6.3.gem", "rack-2.0.3.gem", "hoe-3.0.0.gem", "atomic-1.1.16.gem"]) do |store|
output = subprocess_output(<<-'END', store: store, lock_path: lockfile.path, gemfile_content: gemfile_content)
loader = Gel::LockLoader.new(lock_path, Gel::GemfileParser.parse(gemfile_content))
loader.activate(Gel::Environment, store)
Expand Down

0 comments on commit c7f6106

Please sign in to comment.