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
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
10 11 12 13 14 15 |
# File 'lib/homebrew_automation/source_dist.rb', line 10 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
25 26 27 |
# File 'lib/homebrew_automation/source_dist.rb', line 25 def repo @repo end |
#tag ⇒ String (readonly)
Git tag name, as usable in git
commands
30 31 32 |
# File 'lib/homebrew_automation/source_dist.rb', line 30 def tag @tag end |
#user ⇒ String (readonly)
Github username, as appears in Github URLs
20 21 22 |
# File 'lib/homebrew_automation/source_dist.rb', line 20 def user @user end |
Instance Method Details
#contents ⇒ String
Download and return the file contents.
Lazy and memoized.
46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/homebrew_automation/source_dist.rb', line 46 def contents @contents = @contents || begin resp = @http.get url case resp.code when 200 resp.body.to_s else puts resp raise StandardError.new resp.code end end end |
#sha256 ⇒ String
Calculate and return the file’s checksum.
Lazy and memoized. Download the file if we haven’t already.
37 38 39 |
# File 'lib/homebrew_automation/source_dist.rb', line 37 def sha256 @sha256 ||= Digest::SHA256.hexdigest contents end |
#url ⇒ String
The URL to the source tarball Github generates for tagged commits
63 64 65 |
# File 'lib/homebrew_automation/source_dist.rb', line 63 def url "https://github.com/#{@user}/#{@repo}/archive/#{@tag}.tar.gz" end |