Class: Targit::Asset
Overview
Define asset object for a release
Instance Attribute Summary collapse
-
#asset ⇒ Object
readonly
Returns the value of attribute asset.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#release ⇒ Object
readonly
Returns the value of attribute release.
Instance Method Summary collapse
- #already_exists? ⇒ Boolean
- #delete! ⇒ Object
- #github_data ⇒ Object
-
#initialize(asset, repo, tag, params = {}) ⇒ Asset
constructor
A new instance of Asset.
-
#upload!(retries = 2) ⇒ Object
rubocop:disable Metrics/AbcSize.
- #url ⇒ Object
Constructor Details
#initialize(asset, repo, tag, params = {}) ⇒ Asset
Returns a new instance of Asset.
13 14 15 16 17 18 19 20 |
# File 'lib/targit/asset.rb', line 13 def initialize(asset, repo, tag, params = {}) @options = params @options[:client] ||= client @release = _release repo, tag @asset = asset @upload_options = @name = @options[:name] || File.basename(@asset) end |
Instance Attribute Details
#asset ⇒ Object (readonly)
Returns the value of attribute asset.
11 12 13 |
# File 'lib/targit/asset.rb', line 11 def asset @asset end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
11 12 13 |
# File 'lib/targit/asset.rb', line 11 def name @name end |
#release ⇒ Object (readonly)
Returns the value of attribute release.
11 12 13 |
# File 'lib/targit/asset.rb', line 11 def release @release end |
Instance Method Details
#already_exists? ⇒ Boolean
35 36 37 |
# File 'lib/targit/asset.rb', line 35 def already_exists? github_data != nil end |
#delete! ⇒ Object
39 40 41 42 43 |
# File 'lib/targit/asset.rb', line 39 def delete! asset = github_data return unless asset client.delete_release_asset asset[:url] end |
#github_data ⇒ Object
45 46 47 |
# File 'lib/targit/asset.rb', line 45 def github_data client.release_assets(@release.data[:url]).find { |x| x[:name] == @name } end |
#upload!(retries = 2) ⇒ Object
rubocop:disable Metrics/AbcSize
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/targit/asset.rb', line 22 def upload!(retries = 2) # rubocop:disable Metrics/AbcSize delete! if @options[:force] raise('Release asset already exists') if already_exists? asset = client.upload_asset @release.data[:url], @asset, @upload_options sleep 1 client.release_asset asset[:url] rescue Faraday::ConnectionFailed, Faraday::TimeoutError raise if retries.zero? puts "Retrying upload for #{@asset}" sleep 5 upload!(retries - 1) end |
#url ⇒ Object
49 50 51 52 |
# File 'lib/targit/asset.rb', line 49 def url data = github_data data ? data[:browser_download_url] : raise('Asset URL not found') end |