diff --git a/lib/gel/gemfile_parser.rb b/lib/gel/gemfile_parser.rb index 44ced05..c35beb5 100644 --- a/lib/gel/gemfile_parser.rb +++ b/lib/gel/gemfile_parser.rb @@ -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 @@ -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 diff --git a/test/gemfile_parser_test.rb b/test/gemfile_parser_test.rb index 96b7d80..6503ae8 100644 --- a/test/gemfile_parser_test.rb +++ b/test/gemfile_parser_test.rb @@ -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" @@ -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 @@ -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"