Class: HomebrewAutomation::SourceDist
- Inherits:
-
Object
- Object
- HomebrewAutomation::SourceDist
- Defined in:
- lib/homebrew_automation/source_dist.rb
Overview
A representation of a source distribution tarball file
Defined Under Namespace
Classes: Error, SdistDoesNotExist
Instance Attribute Summary collapse
-
#repo ⇒ String
readonly
Github repo name, as appears in Github URLs.
-
#tag ⇒ String
readonly
Git tag name, as usable in
git
commands. -
#user ⇒ String
readonly
Github username, as appears in Github URLs.
Instance Method Summary collapse
-
#contents ⇒ String
Download and return the file contents.
- #initialize(user, repo, tag, http: RestClient) ⇒ SourceDist constructor
-
#sha256 ⇒ String
Calculate and return the file’s checksum.
-
#url ⇒ String
The URL to the source tarball Github generates for tagged commits.
Constructor Details
#initialize(user, repo, tag, http: RestClient) ⇒ SourceDist
13 14 15 16 17 18 |
# File 'lib/homebrew_automation/source_dist.rb', line 13 def initialize user, repo, tag, http: RestClient @user = user @repo = repo @tag = tag @http = http end |
Instance Attribute Details
#repo ⇒ String (readonly)
Github repo name, as appears in Github URLs
28 29 30 |
# File 'lib/homebrew_automation/source_dist.rb', line 28 def repo @repo end |
#tag ⇒ String (readonly)
Git tag name, as usable in git
commands
33 34 35 |
# File 'lib/homebrew_automation/source_dist.rb', line 33 def tag @tag end |
#user ⇒ String (readonly)
Github username, as appears in Github URLs
23 24 25 |
# File 'lib/homebrew_automation/source_dist.rb', line 23 def user @user end |
Instance Method Details
#contents ⇒ String
Download and return the file contents.
Lazy and memoized.
52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/homebrew_automation/source_dist.rb', line 52 def contents @contents = @contents || begin resp = @http.get url case resp.code when 200 resp.body.to_s else raise Error.new "Other error: HTTP #{resp.code}" end rescue RestClient::NotFound raise SdistDoesNotExist.new end end |
#sha256 ⇒ String
Calculate and return the file’s checksum.
Lazy and memoized. Download the file if we haven’t already.
40 41 42 |
# File 'lib/homebrew_automation/source_dist.rb', line 40 def sha256 @sha256 ||= Digest::SHA256.hexdigest contents end |
#url ⇒ String
The URL to the source tarball Github generates for tagged commits
70 71 72 |
# File 'lib/homebrew_automation/source_dist.rb', line 70 def url "https://github.com/#{@user}/#{@repo}/archive/#{@tag}.tar.gz" end |