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, 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, repo_name, package_name, version_name) ⇒ Version
Returns a new instance of Version.
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_name ⇒ Object (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_name ⇒ Object (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_name ⇒ Object (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.
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_bottles ⇒ Hash
Download metadata about files that exist on Bintray for this Version
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.
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 |