Module: Gem::Home::SpecLoader
- Defined in:
- lib/rubygems/home/spec_loader.rb
Class Method Summary collapse
- .get_docs_url(gem) ⇒ Object
- .get_home_url(gem) ⇒ Object
- .get_issues_url(gem) ⇒ Object
- .github_repo(data) ⇒ Object
- .pull_gemspec(gem) ⇒ Object
- .valid_url?(url) ⇒ Boolean
Class Method Details
.get_docs_url(gem) ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/rubygems/home/spec_loader.rb', line 32 def self.get_docs_url(gem) data = pull_gemspec(gem) link = data["documentation_uri"] return link if link && valid_url?(link) # looks like nobody gave us a documentation url # let's send them to rubydocs return "http://www.rubydoc.info/gems/#{gem}" end |
.get_home_url(gem) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/rubygems/home/spec_loader.rb', line 18 def self.get_home_url(gem) data = pull_gemspec(gem) link = data["homepage_uri"] return link if link && valid_url?(link) # looks like nobody gave us a homepage # are we working with a github link? github_link = github_repo(data) return github_link if github_link # jeeze, not even a github repo. # They don't deserve it, but we'll fall back to rubydocs return "http://www.rubydoc.info/gems/#{gem}" end |
.get_issues_url(gem) ⇒ Object
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/rubygems/home/spec_loader.rb', line 7 def self.get_issues_url(gem) data = pull_gemspec(gem) link = data["bug_tracker_uri"] return link if link && valid_url?(link) # looks like nobody gave us an issue tracker # are we working with a github link? github_link = github_repo(data) return [github_link, "issues"].join("/") if github_link return false end |
.github_repo(data) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/rubygems/home/spec_loader.rb', line 56 def self.github_repo(data) possible = ["homepage_uri", "wiki_uri", "documentation_uri", "source_code_uri", "bug_tracker_uri"] possible.each do |p| link = data[p] if link && link =~ /^(https{0,1}:\/\/)?(www\.)?github\.com/i matches = link.match(/^(https{0,1}:\/\/)?(www\.)?github\.com\/([a-zA-Z]+)\/([a-zA-Z]+)/i) return ["https://github.com", matches[3], matches[4]].join("/") if matches[3] && matches[4] end end return false end |
.pull_gemspec(gem) ⇒ Object
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/rubygems/home/spec_loader.rb', line 41 def self.pull_gemspec(gem) begin result = open("http://rubygems.org/api/v1/gems/#{gem}.json").read return JSON.parse(result) rescue => e puts "Error loading #{gem} gem's spec from rubygems.org" puts e. exit 1 end end |
.valid_url?(url) ⇒ Boolean
52 53 54 |
# File 'lib/rubygems/home/spec_loader.rb', line 52 def self.valid_url?(url) url =~ URI::regexp end |