Method: OpenC3::GemModel.install

Defined in:
lib/openc3/models/gem_model.rb

.install(name_or_path, scope:) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/openc3/models/gem_model.rb', line 77

def self.install(name_or_path, scope:)
  if File.exist?(name_or_path)
    gem_file_path = name_or_path
  else
    gem_file_path = get(name_or_path)
  end
  begin
    rubygems_url = get_setting('rubygems_url', scope: scope)
  rescue
    # If Redis isn't running try the ENV, then simply rubygems.org
    rubygems_url = ENV['RUBYGEMS_URL']
    rubygems_url ||= 'https://rubygems.org'
  end
  Gem.sources = [rubygems_url] if rubygems_url
  Gem.done_installing_hooks.clear
  begin
    # Look for local gems only first, this avoids lengthy timeouts when checking rubygems in airgap env
    Gem.install(gem_file_path, "> 0.pre", build_args: ['--no-document'], prerelease: true, domain: :local)
  rescue Gem::Exception => e
    # If there is a failure look for both local and remote gems
    Gem.install(gem_file_path, "> 0.pre", build_args: ['--no-document'], prerelease: true, domain: :both)
  end
rescue => e
  message = "Gem file #{gem_file_path} error installing to #{ENV['GEM_HOME']}\n#{e.formatted}"
  Logger.error message
  raise e
end