Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RubyMine 6.0.2 with "debugger" gem without modifying Gemfile.lock?

I am using RubyMine (v6.0.2), but my teammates are not, so they need the "debugger" gem in the gemfile. I can conditionally un-require the Gemfile when running RubyMine (so the Gemfile can be shared and identical), but since the 'debugger' gem is not included, the Gemfile.lock file changes depending on whether the project was last run with RubyMine or not. This creates a lot of noise in redundant Gemfile.lock changes.

I've tried using 'debugger-xml' gem; that doesn't solve the issue.

So -- how can I run RubyMine 6.0.2, with the 'debugger' gem in the Gemfile, without having Gemfile.lock change?

like image 219
sellarafaeli Avatar asked Dec 20 '22 19:12

sellarafaeli


1 Answers

I've been working on this issue from the other side of the table. I use the debugger gem, but have team mates that use RubyMine.

We discussed several potential solutions but they all involved conditional checks in the Gemfile that would result in a modified Gemfile.lock.

I googled around for a better solution and found this SO post: How to use gems not in a Gemfile when working with bundler?

Combining a few of the answers in there, I came up with this solution:

  1. Remove the debugger gem from the Gemfile.
  2. Create a Gemfile.local with the contents below.
  3. Add Gemfile.local to the .gitignore file if using git.
  4. Create a function and shell alias.
  5. Start rails with $ be rails s

How it all works!

Bundler will use the file named Gemfile by default, but this behavior can be overridden by specifying a BUNDLE_GEMFILE environment variable. Bundler will use/create the lock file with the same name as the BUNDLE_GEMFILE.

The shell function __bundle_exec_custom will check to see if there is a Gemfile.local file in the CWD. If there is, then the BUNDLE_GEMFILE variable is set and used. Otherwise, the default Gemfile is used.

This will allow a developer to use any gems that they want for local development without having to impact the application as a whole.

Gemfile.local:

source "https://rubygems.org"

gemfile = File.join(File.dirname(__FILE__), 'Gemfile')
if File.readable?(gemfile)
  puts "Loading #{gemfile}..." if $DEBUG
  instance_eval(File.read(gemfile))
end

gem 'debugger'

Function and shell alias:

__bundle_exec_custom () {
  if [ -f Gemfile.local ]
  then
    BUNDLE_GEMFILE="Gemfile.local" bundle exec $@
  else
    bundle exec $@
  fi
}

# Rails aliases
alias be='__bundle_exec_custom'
like image 184
Doug Miller Avatar answered Jan 29 '23 08:01

Doug Miller