Class: HomebrewAutomation::Bintray::Version

Inherits:
Object
  • Object
show all
Defined in:
lib/homebrew_automation/bintray/version.rb

Overview

A representation of a Bintray Version

As per Bintray, a Version is part of a Package is part of a Repository.

Defined Under Namespace

Classes: FileAlreadyExists

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, repo_name, package_name, version_name) ⇒ Version

Returns a new instance of Version.

Parameters:

  • client (Client)

    Connection to Bintray servers

  • repo_name (String)
  • package_name (String)
  • version_name (String)


22
23
24
25
26
27
# File 'lib/homebrew_automation/bintray/version.rb', line 22

def initialize(client, repo_name, package_name, version_name)
  @client = client
  @repo_name = repo_name
  @package_name = package_name
  @version_name = version_name
end

Instance Attribute Details

#package_nameObject (readonly)

Returns the value of attribute package_name.



29
30
31
# File 'lib/homebrew_automation/bintray/version.rb', line 29

def package_name
  @package_name
end

#repo_nameObject (readonly)

Returns the value of attribute repo_name.



29
30
31
# File 'lib/homebrew_automation/bintray/version.rb', line 29

def repo_name
  @repo_name
end

#version_nameObject (readonly)

Returns the value of attribute version_name.



29
30
31
# File 'lib/homebrew_automation/bintray/version.rb', line 29

def version_name
  @version_name
end

Instance Method Details

#_assert_match(cond, x) ⇒ Object



79
80
81
82
83
84
# File 'lib/homebrew_automation/bintray/version.rb', line 79

def _assert_match(cond, x)
  unless cond === x
    p x
    raise StandardError.new(x)
  end
end

#_parse_for_os(bottle_filename) ⇒ String

Returns OS name.

Parameters:

  • bottle_filename (String)

    filename

Returns:

  • (String)

    OS name



88
89
90
91
92
# File 'lib/homebrew_automation/bintray/version.rb', line 88

def _parse_for_os(bottle_filename)
  File.extname(
    File.basename(bottle_filename, '.bottle.tar.gz')).
  sub(/^\./, '')
end

#create!Object

Create this Version

This assumes the Package and Repository already exists. If they do not, consider creating them manually via the Bintray web UI.



35
36
37
# File 'lib/homebrew_automation/bintray/version.rb', line 35

def create!
  @client.create_version(@repo_name, @package_name, @version_name)
end

#gather_bottlesHash

Download metadata about files that exist on Bintray for this Version

Returns:

  • (Hash)

    mapping from OS (as appears in part of the filenames) to sha256 checksum



66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/homebrew_automation/bintray/version.rb', line 66

def gather_bottles
  resp = @client.get_all_files_in_version(@repo_name, @package_name, @version_name)
  _assert_match((200..207), resp.code)
  json = JSON.parse(resp.body)
  _assert_match(Array, json)
  pairs = json.map do |f|
    os = _parse_for_os(f['name'])
    checksum = f['sha256']
    [os, checksum]
  end
  Hash[pairs]
end

#upload_file!(filename, content) ⇒ Object

Upload a file to be part of this Version

This is probably your Homebrew Bottle binary tarball.

Parameters:

  • filename (String)
  • content (String)

    the bytes in the file



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/homebrew_automation/bintray/version.rb', line 45

def upload_file!(filename, content)
  begin
    @client.upload_file(
      @repo_name,
      @package_name,
      @version_name,
      filename,
      content)
  rescue RestClient::ExceptionWithResponse => e
    case e.response.code
    when 409
      raise FileAlreadyExists
    else
      raise e
    end
  end
end