Class: Gemview::GitRepo
- Inherits:
-
Object
- Object
- Gemview::GitRepo
- Defined in:
- lib/gemview/git_repo.rb
Constant Summary collapse
- HOSTS =
[ GITHUB = :github, GITLAB = :gitlab, CODEBERG = :codeberg ].freeze
- HTTPS_PORT =
443
Instance Attribute Summary collapse
-
#base_uri ⇒ Object
readonly
Returns the value of attribute base_uri.
-
#changelog_uri ⇒ Object
readonly
Returns the value of attribute changelog_uri.
-
#git_host ⇒ Object
readonly
Returns the value of attribute git_host.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Class Method Summary collapse
- .from_urls(homepage_uri:, source_code_uri:, changelog_uri:, version:) ⇒ Gemview::GitRepo?
-
.parse_base_uri(uri) ⇒ base_uri as `String` and git_host as `Symbol`
Or nil if unsuccessful.
Instance Method Summary collapse
- #changelog ⇒ String?
- #changelog? ⇒ Boolean
-
#initialize(base_uri:, changelog_uri:, git_host:, version:) ⇒ GitRepo
constructor
A new instance of GitRepo.
- #readme ⇒ String?
- #readme? ⇒ Boolean
Constructor Details
#initialize(base_uri:, changelog_uri:, git_host:, version:) ⇒ GitRepo
Returns a new instance of GitRepo.
54 55 56 57 58 59 60 61 |
# File 'lib/gemview/git_repo.rb', line 54 def initialize(base_uri:, changelog_uri:, git_host:, version:) raise ArgumentError, "Invalid host: #{git_host}" unless HOSTS.include?(git_host) @base_uri = base_uri.dup.freeze @changelog_uri = changelog_uri.dup.freeze @git_host = git_host @version = version.dup.freeze end |
Instance Attribute Details
#base_uri ⇒ Object (readonly)
Returns the value of attribute base_uri.
48 49 50 |
# File 'lib/gemview/git_repo.rb', line 48 def base_uri @base_uri end |
#changelog_uri ⇒ Object (readonly)
Returns the value of attribute changelog_uri.
48 49 50 |
# File 'lib/gemview/git_repo.rb', line 48 def changelog_uri @changelog_uri end |
#git_host ⇒ Object (readonly)
Returns the value of attribute git_host.
48 49 50 |
# File 'lib/gemview/git_repo.rb', line 48 def git_host @git_host end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
48 49 50 |
# File 'lib/gemview/git_repo.rb', line 48 def version @version end |
Class Method Details
.from_urls(homepage_uri:, source_code_uri:, changelog_uri:, version:) ⇒ Gemview::GitRepo?
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/gemview/git_repo.rb', line 18 def self.from_urls(homepage_uri:, source_code_uri:, changelog_uri:, version:) [homepage_uri, source_code_uri, changelog_uri].compact.each do |uri| base_uri, git_host = parse_base_uri(uri) if base_uri && git_host return new( base_uri: base_uri, changelog_uri: changelog_uri, git_host: git_host, version: version ) end end nil end |
.parse_base_uri(uri) ⇒ base_uri as `String` and git_host as `Symbol`
Returns or nil if unsuccessful.
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/gemview/git_repo.rb', line 35 def self.parse_base_uri(uri) github_base_uri = uri[%r{^https?://github\.com/[^/]+/[^/]+}, 0] return [github_base_uri, GITHUB] if github_base_uri gitlab_base_uri = uri[%r{^https?://gitlab\.com/[^/]+/[^/]+}, 0] return [gitlab_base_uri, GITLAB] if gitlab_base_uri codeberg_base_uri = uri[%r{^https?://codeberg\.org/[^/]+/[^/]+}, 0] [codeberg_base_uri, CODEBERG] if codeberg_base_uri end |
Instance Method Details
#changelog ⇒ String?
77 78 79 80 81 82 83 84 85 86 |
# File 'lib/gemview/git_repo.rb', line 77 def changelog return @changelog if defined?(@changelog) filenames = [changelog_filename, "CHANGELOG.md"].compact.uniq filenames.each do |filename| break if (@changelog = fetch_raw_file(filename)) end @changelog end |
#changelog? ⇒ Boolean
74 |
# File 'lib/gemview/git_repo.rb', line 74 def changelog? = !defined?(@changelog) || !changelog.nil? |
#readme ⇒ String?
67 68 69 70 71 |
# File 'lib/gemview/git_repo.rb', line 67 def readme return @readme if defined?(@readme) @readme = fetch_raw_file("README.md") end |
#readme? ⇒ Boolean
64 |
# File 'lib/gemview/git_repo.rb', line 64 def readme? = !defined?(@readme) || !readme.nil? |