class HomebrewAutomation::SourceDist

A representation of a source distribution tarball file

Attributes

repo[R]

Github repo name, as appears in Github URLs

@return [String]

tag[R]

Git tag name, as usable in git commands

@return [String]

user[R]

Github username, as appears in Github URLs

@return [String]

Public Class Methods

new(user, repo, tag, http: RestClient) click to toggle source

Assign args to attributes {#user}, {#repo}, {#tag}

# 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

Public Instance Methods

contents() click to toggle source

Download and return the file contents.

Lazy and memoized.

@return [String] contents of the file

# 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() click to toggle source

Calculate and return the file's checksum.

Lazy and memoized. Download the file if we haven't already.

@return [String] hex-encoded string representation of the checksum

# File lib/homebrew_automation/source_dist.rb, line 40
def sha256
  @sha256 ||= Digest::SHA256.hexdigest contents
end
url() click to toggle source

The URL to the source tarball Github generates for tagged commits

@return [String]

# File lib/homebrew_automation/source_dist.rb, line 70
def url
  "https://github.com/#{@user}/#{@repo}/archive/#{@tag}.tar.gz"
end