How to use gems not in a Gemfile when working with bundler?

前端 未结 6 1378
失恋的感觉
失恋的感觉 2020-12-28 15:18

When using bundler with a project in general and Rails specifically, you have access only to gems defined in your Gemfile. While this makes sense, it can be limiting. Mostly

6条回答
  •  没有蜡笔的小新
    2020-12-28 15:54

    In ChiliProject we allow users to create a Gemfile.local which is included into the main Gemfile on load. This allows users to specify additional gems without having to change our Gemfile to ease updates.

    For that, we have included the following code at the bottom of our Gemfile.

    gemfile_local = File.expand_path('Gemfile.local', __dir__)
    if File.readable?(gemfile_local)
      puts "Loading #{gemfile_local}..." if $DEBUG
      instance_eval(File.read(gemfile_local))
    end
    

    The Gemfile.local itself is excluded from the repository via .gitignore.

提交回复
热议问题