有没有办法通过路径选项检测环境中哪些宝石已从源加载?
即:
# 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
答案 0 :(得分:1)
使用Path class from Bundler,以下工作:
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 }