Class: CompareLinker::GithubLinkFinder
- Inherits:
-
Object
- Object
- CompareLinker::GithubLinkFinder
- Defined in:
- lib/compare_linker/github_link_finder.rb
Instance Attribute Summary collapse
-
#gem_dictionary ⇒ Object
readonly
Returns the value of attribute gem_dictionary.
-
#homepage_uri ⇒ Object
readonly
Returns the value of attribute homepage_uri.
-
#octokit ⇒ Object
readonly
Returns the value of attribute octokit.
-
#repo_name ⇒ Object
readonly
Returns the value of attribute repo_name.
-
#repo_owner ⇒ Object
readonly
Returns the value of attribute repo_owner.
Instance Method Summary collapse
- #find(gem_name) ⇒ Object
-
#initialize(octokit, gem_dictionary) ⇒ GithubLinkFinder
constructor
A new instance of GithubLinkFinder.
- #repo_full_name ⇒ Object
Constructor Details
#initialize(octokit, gem_dictionary) ⇒ GithubLinkFinder
Returns a new instance of GithubLinkFinder.
9 10 11 12 |
# File 'lib/compare_linker/github_link_finder.rb', line 9 def initialize(octokit, gem_dictionary) @octokit = octokit @gem_dictionary = gem_dictionary end |
Instance Attribute Details
#gem_dictionary ⇒ Object (readonly)
Returns the value of attribute gem_dictionary.
7 8 9 |
# File 'lib/compare_linker/github_link_finder.rb', line 7 def gem_dictionary @gem_dictionary end |
#homepage_uri ⇒ Object (readonly)
Returns the value of attribute homepage_uri.
7 8 9 |
# File 'lib/compare_linker/github_link_finder.rb', line 7 def homepage_uri @homepage_uri end |
#octokit ⇒ Object (readonly)
Returns the value of attribute octokit.
7 8 9 |
# File 'lib/compare_linker/github_link_finder.rb', line 7 def octokit @octokit end |
#repo_name ⇒ Object (readonly)
Returns the value of attribute repo_name.
7 8 9 |
# File 'lib/compare_linker/github_link_finder.rb', line 7 def repo_name @repo_name end |
#repo_owner ⇒ Object (readonly)
Returns the value of attribute repo_owner.
7 8 9 |
# File 'lib/compare_linker/github_link_finder.rb', line 7 def repo_owner @repo_owner end |
Instance Method Details
#find(gem_name) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/compare_linker/github_link_finder.rb', line 14 def find(gem_name) gem_info = JSON.parse( HTTPClient.get_content("https://rubygems.org/api/v1/gems/#{gem_name}.json") ) github_url = [ gem_info["homepage_uri"], gem_info["source_code_uri"] ].find { |uri| uri.to_s.match(/github\.com\//) } if github_url = redirect_url(github_url) _, @repo_owner, @repo_name = github_url.match(%r!github\.com/([^/]+)/([^/#]+)!).to_a else @repo_owner, @repo_name = gem_dictionary.lookup(gem_info["name"]) @homepage_uri = gem_info["homepage_uri"] end rescue HTTPClient::BadResponseError @homepage_uri = "https://rubygems.org/gems/#{gem_name}" end |
#repo_full_name ⇒ Object
35 36 37 |
# File 'lib/compare_linker/github_link_finder.rb', line 35 def repo_full_name "#{@repo_owner}/#{repo_name}" end |