0

In my team, some people like to use the pry-rails gem and others don't like it.

Is there a way to have a secondary Gemfile for development where I don't commit it to git and is still read by bundler?

11
  • don't think its possible, but somehow you can hide it from git.
    – Anand
    May 25, 2018 at 10:38
  • @Gabbar how to hide it from git?
    – Shobhit
    May 25, 2018 at 10:59
  • @Shobhit I think he is taking about .gitignore May 25, 2018 at 11:03
  • 2
    I would suggest conditionally requiring it via an environment variable then, rather than conditionally including it in the Gemfile. The answer below has one big problem: Developers will keep updating the Gemfile.lock and accidentally checking it into source control!
    – Tom Lord
    May 25, 2018 at 12:26
  • 4
    @Shobhit The real solution for your specific underlying problem with this gem is: Include pry-rails in your gemfile for everybody, and people who don't like it can explicitly suppress it with export DISABLE_PRY_RAILS=1 in their .bash_profile. pry-rails already supports this opt-out, you don't need to introduce a second gemfile just to selectively include/exclude this gem.
    – user229044
    May 25, 2018 at 12:58

2 Answers 2

10

You can run:

BUNDLE_GEMFILE=/path/to/another/gemfile bundle install 

Or in Gemfile (will create conflict with committed Gemfile.lock) :

gem 'pry-rails' if ENV['WITH_PRY']

And populate WITH_PRY env variable to enable pry.

Another solution to avoid Gemfile.lock conflict with Rails app :

# In Gemfile
group :dev_with_pry do
  gem 'pry-rails'
end

And add dev_with_pry to RAILS_GROUPS env variable, this will install the gem but not require it.

3
  • Thanks, this looks like a good solution for my problem.
    – Shobhit
    May 25, 2018 at 12:22
  • This is going to introduce some weird problems with Gemfile.lock that some developers are going to have to remember not to commit, as Tom Lord already pointed out above.
    – user229044
    May 25, 2018 at 12:32
  • I added another solution to avoid Gemfile.lock conflict
    – D1ceWard
    May 25, 2018 at 13:00
0

As per the specifications shared you can manage by having two gemfiles and requiring them based on environment.

Gemfile

source 'https://rubygems.org'
gemfiles = [ 'Gemfile1', 'Gemfile2' ]
gemfiles.each do |gemfile|
    instance_eval File.read(gemfile)
  end
end

Now you can have two separate Gemfile such as

Gemfile1

source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.0.1'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'

# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.0'

# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'

# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'

# gem 'therubyracer', platforms: :ruby

# Use jquery as the JavaScript library
gem 'jquery-rails'

gem 'pry'

Then other gems can be added in Gemfile2

Gemfile 2

source 'https://rubygems.org'

https://github.com/rails/turbolinks
gem 'turbolinks'
gem 'jbuilder', '~> 1.2'

group :doc do
 gem 'sdoc', require: false
end

Hope it Helps!!

Not the answer you're looking for? Browse other questions tagged or ask your own question.