Class: Targit::Asset
Overview
Define asset object for a release
Instance Attribute Summary collapse
-
#asset ⇒ Object
readonly
Returns the value of attribute asset.
-
#github_data ⇒ Object
readonly
Returns the value of attribute github_data.
-
#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
-
#initialize(asset, repo, tag, params = {}) ⇒ Asset
constructor
A new instance of Asset.
- #upload! ⇒ Object
- #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 = {}) = params [:client] ||= client @release = _release repo, tag @asset = asset = @name = [: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 |
#github_data ⇒ Object (readonly)
Returns the value of attribute github_data.
11 12 13 |
# File 'lib/targit/asset.rb', line 11 def github_data @github_data 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
29 30 31 |
# File 'lib/targit/asset.rb', line 29 def already_exists? github_data != nil end |
#delete! ⇒ Object
33 34 35 36 37 |
# File 'lib/targit/asset.rb', line 33 def delete! asset = github_data return unless asset client.delete_release_asset asset[:url] end |
#upload! ⇒ Object
22 23 24 25 26 27 |
# File 'lib/targit/asset.rb', line 22 def upload! delete! if [:force] raise('Release asset already exists') if already_exists? asset = client.upload_asset @release.data[:url], @asset, client.release_asset asset[:url] end |
#url ⇒ Object
43 44 45 46 |
# File 'lib/targit/asset.rb', line 43 def url data = github_data data ? data[:browser_download_url] : raise('Asset URL not found') end |