class HomebrewAutomation::Bintray::Version

A representation of a Bintray Version

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

Attributes

package_name[R]
repo_name[R]
version_name[R]

Public Class Methods

new(client, logger, repo_name, package_name, version_name) click to toggle source

@param client [Client] Connection to Bintray servers @param logger [HomebrewAutomation::Logger] @param repo_name [String] @param package_name [String] @param version_name [String]

# File lib/homebrew_automation/bintray/version.rb, line 23
def initialize(client, logger, repo_name, package_name, version_name)
  @client = client
  @logger = logger
  @repo_name = repo_name
  @package_name = package_name
  @version_name = version_name
end

Public Instance Methods

_assert_match(cond, x) click to toggle source
# File lib/homebrew_automation/bintray/version.rb, line 82
def _assert_match(cond, x)
  unless cond === x
    p x
    raise StandardError.new(x)
  end
end
_parse_for_os(bottle_filename) click to toggle source

@param bottle_filename [String] filename @return [String] OS name

# File lib/homebrew_automation/bintray/version.rb, line 91
def _parse_for_os(bottle_filename)
  File.extname(
    File.basename(bottle_filename, '.bottle.tar.gz')).
  sub(/^\./, '')
end
create!() click to toggle source

Create this Version

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

# File lib/homebrew_automation/bintray/version.rb, line 37
def create!
  @client.create_version(@repo_name, @package_name, @version_name)
end
gather_bottles() click to toggle source

Download metadata about files that exist on Bintray for this Version

@return [Hash] mapping from OS (as appears in part of the filenames) to sha256 checksum

# File lib/homebrew_automation/bintray/version.rb, line 68
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)
  @logger.info!("All files in Bintray Version: #{json}")
  _assert_match(Array, json)
  pairs = json.map do |f|
    os = _parse_for_os(f['name'])
    checksum = f['sha256']
    [os, checksum]
  end.select { |o, _| not o.empty? }
  Hash[pairs]
end
upload_file!(filename, content) click to toggle source

Upload a file to be part of this Version

This is probably your Homebrew Bottle binary tarball.

@param filename [String] @param content [String] the bytes in the file

# File lib/homebrew_automation/bintray/version.rb, line 47
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