module SigtermExtensions::GemMethods
Public Instance Methods
add_gems_global_to_path()
click to toggle source
# File lib/sigterm_extensions/gem_methods.rb, line 33 def add_gems_global_to_path # This will load all global gems to load path if defined?(::Bundler) global_gemset = ENV['GEM_PATH'].split(':').grep(/ruby.*@global/).first if global_gemset all_global_gem_paths = Dir.glob("#{global_gemset}/gems/*") all_global_gem_paths.each do |p| gem_path = "#{p}/lib" $LOAD_PATH << gem_path end end end end
load_everything!()
click to toggle source
# File lib/sigterm_extensions/gem_methods.rb, line 25 def load_everything! Gem::Specification.all.each do |gem| gem.load_paths.each do |p| $:.unshift(p) unless $LOAD_PATH.include?(p) end end end
unbundled_require(gem) { || ... }
click to toggle source
This can require a gem that's not in the Gemfile or gemspec
# File lib/sigterm_extensions/gem_methods.rb, line 5 def unbundled_require(gem) if defined?(::Bundler) spec_path = Dir.glob("#{Gem.dir}/specifications/#{gem}-*.gemspec").last if spec_path.nil? warn "Couldn't find #{gem}" return end spec = Gem::Specification.load spec_path spec.activate end begin require gem yield if block_given? rescue Exception => err warn "Couldn't load #{gem}: #{err}" end end