Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow multilevel values for group, platforms and install_if #71

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions lib/gel/gemfile_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,21 @@ def initialize(filename)
def flatten(options, stack)
options = options.dup
stack.reverse_each do |layer|
options.update(layer) { |_, current, outer| current }
options.update(layer) { |_, current, outer| Array(outer) + Array(current) }
end

@git_sources.each do |key, block|
next unless options.key?(key)
raise "Multiple git sources specified" if options.key?(:git)
options[:git] = block.call(options.delete(key))
end

if options[:install_if]
options[:install_if] = Array(options[:install_if]).all? do |condition|
condition.respond_to?(:call) ? condition.call : condition
end
end

options
end

Expand All @@ -158,12 +166,6 @@ def add_gem(name, requirements, options)
raise "Only git sources can specify a :branch" if options[:branch] && !options[:git]
raise "Duplicate entry for gem #{name.inspect}" if @gems.assoc(name)

if options[:install_if]
options[:install_if] = Array(options[:install_if]).all? do |condition|
condition.respond_to?(:call) ? condition.call : condition
end
end

@gems << [name, requirements, options]
end

Expand Down
14 changes: 7 additions & 7 deletions test/gemfile_parser_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ class GemfileParserTest < Minitest::Test
end

group :test do
gem "minitest-bisect"
gem "minitest-bisect", group: :development

platforms :mri do
gem "stackprof"
gem "byebug"
gem "byebug", platforms: :rbx
end

gem "benchmark-ips"
Expand All @@ -42,10 +42,10 @@ def test_simple_parse
["rake", [">= 11.1"], {}],
["mocha", [], require: false],
["bcrypt", ["~> 3.1.11"], require: false],
["w3c_validators", [], group: [:doc], require: "w3c_validators/validator"],
["minitest-bisect", [], group: [:test]],
["w3c_validators", [], require: "w3c_validators/validator", group: [:doc]],
["minitest-bisect", [], group: [:test, :development]],
["stackprof", [], platforms: [:mri], group: [:test]],
["byebug", [], platforms: [:mri], group: [:test]],
["byebug", [], platforms: [:mri, :rbx], group: [:test]],
["benchmark-ips", [], group: [:test]],
["rails-assets-bootstrap", [], source: "https://rails-assets.org"],
], result.gems
Expand Down Expand Up @@ -149,8 +149,8 @@ def test_install_if
gem "activesupport", "2.3.5"
end
gem "thin", :install_if => lambda { false }
install_if lambda { false } do
gem "foo"
install_if true, lambda { nil } do
gem "foo", :install_if => true
end
gem "bar", :install_if => [true, lambda { 1 }]
gem "rack"
Expand Down