Class: Targit::Asset

Inherits:
Object
  • Object
show all
Includes:
Client
Defined in:
lib/targit/asset.rb

Overview

Define asset object for a release

Instance Attribute Summary collapse

Instance Method Summary collapse

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 = _upload_options
  @name = @options[:name] || File.basename(@asset)
end

Instance Attribute Details

#assetObject (readonly)

Returns the value of attribute asset.



11
12
13
# File 'lib/targit/asset.rb', line 11

def asset
  @asset
end

#github_dataObject (readonly)

Returns the value of attribute github_data.



11
12
13
# File 'lib/targit/asset.rb', line 11

def github_data
  @github_data
end

#nameObject (readonly)

Returns the value of attribute name.



11
12
13
# File 'lib/targit/asset.rb', line 11

def name
  @name
end

#releaseObject (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

Returns:

  • (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 @options[:force]
  raise('Release asset already exists') if already_exists?
  asset = client.upload_asset @release.data[:url], @asset, @upload_options
  client.release_asset asset[:url]
end

#urlObject



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