Supporting ligament bypass

In the Gemfile my Rails project, I am starting to have helper gems such as "ruby-debug19", "perftools.rb" or "irbtools". All of them really have nothing to do with the project, but rather are part of my local development. But since I use bundler, I cannot download these gems (even if they are installed on a system scale) unless I add them to the Gemfile. In my opinion, this is a bit of code smell.

For example, I would like to be able to require 'irbtools' in the rails console without adding "irbtools" to my Gemfile.

Is there a way to save helper stones from the Gemfile and still be able to load them for debugging, profiling, etc., when I need them?

+8
ruby ruby-on-rails rubygems bundler
source share
4 answers

Actually, you can create group in the Gemfile , for example:

 group :auxiliary do gem 'irbtools' end 

And then use bundle install --without auxiliary if you don't want to use irbtools . Why do you think adding them to the Gemfile is a smell of code? And if it is possible to do this without adding gems to the Gemfile , it will be much more of a code smell, I think.

+3
source share

Thanks to this post I have a great solution.

  • Add this line to the end of your gemfile:

     eval(File.read(File.dirname(__FILE__) + '/Gemfile.local'), binding) rescue nil 
  • Create a file called Gemfile.local.

  • Add your development stones to Gemfile local. For example:

     group :development do gem 'cucumber' end 
  • Add Gemfile.local to .gitignore.

Now you can add your supporting development without changing the Gemfile for other people in the team. Very cool.

+3
source share

I put the code below in a file in my application root, so it is easy to download from irb .

If you want something like a rails server, you probably need to add a load statement to environments/development.rb , etc. This still creates problems if you accidentally check it out, but it is less annoying than adding it to the Gemfile and you will also modify your Gemfile.lock.

 # Example usage: # add_more_gems("ruby-debug-base19-0.11.26", "linecache19-0.5.13") # or # add_more_gems(%w(ruby-debug-base19-0.11.26 linecache19-0.5.13)) # # Note that you are responsible for: # - adding all gem dependencies manually # - making sure manually-added gem versions don't conflict with Gemfile.lock # To list deps, run eg "gem dep ruby-debug-base19 -v 0.11.26" # def add_more_gems(*gem_names_and_vers) gem_names_and_vers.flatten! gem_base = File.expand_path(Gem.dir) gem_names_and_vers.each do |gem_name_and_ver| # uncomment if desired ###puts "Adding lib paths for #{gem_name_and_ver.inspect}" spec_file = File.join(gem_base, 'specifications', "#{gem_name_and_ver}.gemspec") spec = Gem::Specification.load spec_file this_gem_dir = File.join(gem_base, 'gems', gem_name_and_ver) spec.require_paths.each {|path| dir_to_add = File.join(this_gem_dir, path) $: << dir_to_add unless $:.member?(dir_to_add) } end end # put your often-used gems here add_more_gems( %w( ruby-debug-base19-0.11.26 ruby-debug-ide19-0.4.12 linecache19-0.5.13 ) ) 
+2
source share

Not sure if this will work for you. It depends on whether you use RVM or not. If so, then you can set these helper gems in the gemset @global , which is created automatically for each Ruby interpreter. Gems in gemset @global are available by default for all gemet projects. This way you will not need to clutter up your gemfiles.

0
source share

All Articles