Module: OpenVoxAgentRubygems

Defined in:
lib/openvox_agent_rubygems.rb

Class Method Summary collapse

Class Method Details

.activate!Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/openvox_agent_rubygems.rb', line 6

def self.activate!
  return false unless packaged_agent_ruby?

  unless ENV.key?('GEM_HOME') || ENV.key?('GEM_PATH')
    restore_paths!
    return !@gem_paths.nil?
  end

  original_paths = Gem.path
  ENV.delete('GEM_HOME')
  ENV.delete('GEM_PATH')
  Gem.clear_paths

  agent_paths = Gem.path.reject { |path| user_ruby_path?(path) }
  preserved_paths = original_paths.reject { |path| user_ruby_path?(path) }
  combined_paths = (preserved_paths + agent_paths).uniq
  @gem_home = combined_paths.first
  @gem_paths = combined_paths
  restore_paths!
  add_gem_require_paths!(preserved_paths)
  true
end

.restore_paths!Object



29
30
31
32
33
34
35
# File 'lib/openvox_agent_rubygems.rb', line 29

def self.restore_paths!
  return false unless packaged_agent_ruby?
  return false if @gem_paths.nil?

  Gem.use_paths(@gem_home, @gem_paths) unless Gem.path == @gem_paths
  true
end