Class: HomebrewAutomation::SourceDist

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(user, repo, tag, http: RestClient) ⇒ SourceDist

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



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

#repoString (readonly)

Github repo name, as appears in Github URLs

Returns:

  • (String)


28
29
30
# File 'lib/homebrew_automation/source_dist.rb', line 28

def repo
  @repo
end

#tagString (readonly)

Git tag name, as usable in git commands

Returns:

  • (String)


33
34
35
# File 'lib/homebrew_automation/source_dist.rb', line 33

def tag
  @tag
end

#userString (readonly)

Github username, as appears in Github URLs

Returns:

  • (String)


23
24
25
# File 'lib/homebrew_automation/source_dist.rb', line 23

def user
  @user
end

Instance Method Details

#contentsString

Download and return the file contents.

Lazy and memoized.

Returns:

  • (String)

    contents of the file



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

#sha256String

Calculate and return the file’s checksum.

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

Returns:

  • (String)

    hex-encoded string representation of the checksum



40
41
42
# File 'lib/homebrew_automation/source_dist.rb', line 40

def sha256
  @sha256 ||= Digest::SHA256.hexdigest contents
end

#urlString

The URL to the source tarball Github generates for tagged commits

Returns:

  • (String)


70
71
72
# File 'lib/homebrew_automation/source_dist.rb', line 70

def url
  "https://github.com/#{@user}/#{@repo}/archive/#{@tag}.tar.gz"
end