rubygems / bundler-features

Bundler feature requests and discussion
28 stars 8 forks source link

Arbitrary Gemfile conditionals #77

Closed skull-squadron closed 9 years ago

skull-squadron commented 9 years ago

Just encountered this use-case again, so here's my 20 millicents.

Another possible solution (compared to https://github.com/bundler/bundler/issues/1636) for conditionals to support bundle package --all could be:

group :db_sqlite, condition: -> { driver? 'sqlite' } do
  gem 'sqlite3'
end

group :db_postgres, condition: -> { driver? 'postgres' } do
  gem 'pg'
end

# or simply

condition: -> { driver? 'postgres' } do
  gem 'pg'
end

# one-off

gem 'rails_12factor', condition: -> { ENV.keys.grep(/HEROKU/).any? }

Such that the lambda is evaluated sometime after Bundler is completely loaded, and the block happens if the lambda returns truthy (so inside the lambda might be your own DSL: driver? for example).

And then somehow augment Gemfile.lock to include a bit of ruby (the contents of the lambda) (Yea security or functionality, pick 1.5)

That way, prod, dev, whatever will run idempotently and as expected, and also arbitrary expressions can be used without breaking package --all. This makes bundler sufficiently general without going too crazy, just a little batters with ruby in the yaml.

See also: