Module: Gems::RubyGems
- Defined in:
- lib/repo_conf_generators/gem_conf_generators.rb
Class Method Summary collapse
-
.generate(description, base_urls, frozen_date = "latest") ⇒ Object
The different generate classes will always generate an exception (“string”) if there’s anything that went wrong.
Class Method Details
.generate(description, base_urls, frozen_date = "latest") ⇒ Object
The different generate classes will always generate an exception (“string”) if there’s anything that went wrong. If no exception, things went well.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/repo_conf_generators/gem_conf_generators.rb', line 42 def self.generate(description, base_urls, frozen_date="latest") #1 - get the current sources initial_sources= Gems.gem('sources', '--list').split("\n") initial_sources.reject!{|s| s =~ /^\*\*\*/ || s.chomp == "" } # Discard the message (starting with ***) and empty lines returned by gem sources #2- Add our sources repo_path = "archive/"+ (frozen_date || "latest") mirror_list = base_urls.map do |bu| bu +='/' unless bu[-1..-1] == '/' # ensure the base url is terminated with a '/' bu+repo_path+ ( repo_path[-1..-1] == '/'? "":"/") end sources_to_delete = initial_sources-mirror_list # remove good sources from later deletion if we're gonna add them right now. mirror_list.map do |m| begin puts "Adding gem source: #{m}" Gems.gem('sources', '--add', m) rescue Exception => e puts "Error Adding gem source #{m}: #{e}\n...continuing with others..." end end #3-Delete the initial ones (that don't overlap with the new ones) sources_to_delete.map do |m| begin puts "Removing stale gem source: #{m}" Gems.gem('sources', '--remove', m) rescue Exception => e puts "Error Adding gem source #{m}: #{e}\n...continuing with others..." end end mirror_list end |