1

有没有办法通过路径选项检测环境中的哪些 gem 是从源代码加载的?

IE:

# Gemfile
source 'rubygems.org'

gem 'rails'
gem 'rails-extension', path: '~/code/rails-extension'

.

# some_script.rb
require 'rubygems'

ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)

require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE']) 

if defined?(Bundler) and not Bundler.sourced_gems.empty?
  puts "Using gems from source. Not safe to push to origin."
end      
4

1 回答 1

1

使用Bundler 中的 Path 类,以下工作:

require 'rubygems'

ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)

require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])


Gem.loaded_specs.values.map { |g| puts "#{g.name} from #{g.source}. Not safe to push to origin." if g.source.instance_of? Bundler::Source::Path }
于 2013-05-16T08:06:17.670 回答