Class: HomebrewAutomation::Bintray::Version
- Inherits:
-
Object
- Object
- HomebrewAutomation::Bintray::Version
- 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
-
#package_name ⇒ Object
readonly
Returns the value of attribute package_name.
-
#repo_name ⇒ Object
readonly
Returns the value of attribute repo_name.
-
#version_name ⇒ Object
readonly
Returns the value of attribute version_name.
Instance Method Summary collapse
- #_assert_match(cond, x) ⇒ Object
-
#_parse_for_os(bottle_filename) ⇒ String
OS name.
-
#create! ⇒ Object
Create this
Version
. -
#gather_bottles ⇒ Hash
Download metadata about files that exist on Bintray for this
Version
. -
#initialize(client, logger, repo_name, package_name, version_name) ⇒ Version
constructor
A new instance of Version.
-
#upload_file!(filename, content) ⇒ Object
Upload a file to be part of this
Version
.
Constructor Details
#initialize(client, logger, repo_name, package_name, version_name) ⇒ Version
Returns a new instance of Version.
23 24 25 26 27 28 29 |
# 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 |
Instance Attribute Details
#package_name ⇒ Object (readonly)
Returns the value of attribute package_name.
31 32 33 |
# File 'lib/homebrew_automation/bintray/version.rb', line 31 def package_name @package_name end |
#repo_name ⇒ Object (readonly)
Returns the value of attribute repo_name.
31 32 33 |
# File 'lib/homebrew_automation/bintray/version.rb', line 31 def repo_name @repo_name end |
#version_name ⇒ Object (readonly)
Returns the value of attribute version_name.
31 32 33 |
# File 'lib/homebrew_automation/bintray/version.rb', line 31 def version_name @version_name end |
Instance Method Details
#_assert_match(cond, x) ⇒ Object
82 83 84 85 86 87 |
# 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) ⇒ String
Returns OS name.
91 92 93 94 95 |
# 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! ⇒ 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.
37 38 39 |
# File 'lib/homebrew_automation/bintray/version.rb', line 37 def create! @client.create_version(@repo_name, @package_name, @version_name) end |
#gather_bottles ⇒ Hash
Download metadata about files that exist on Bintray for this Version
68 69 70 71 72 73 74 75 76 77 78 79 80 |
# 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) ⇒ Object
Upload a file to be part of this Version
This is probably your Homebrew Bottle binary tarball.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# 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 |