Class: Javy::Asset

Inherits:
Struct
  • Object
show all
Defined in:
ext/javy/javy.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#basenameObject

Returns the value of attribute basename

Returns:

  • (Object)

    the current value of basename



107
108
109
# File 'ext/javy/javy.rb', line 107

def basename
  @basename
end

#ownerObject

Returns the value of attribute owner

Returns:

  • (Object)

    the current value of owner



107
108
109
# File 'ext/javy/javy.rb', line 107

def owner
  @owner
end

#platformObject

Returns the value of attribute platform

Returns:

  • (Object)

    the current value of platform



107
108
109
# File 'ext/javy/javy.rb', line 107

def platform
  @platform
end

#repositoryObject

Returns the value of attribute repository

Returns:

  • (Object)

    the current value of repository



107
108
109
# File 'ext/javy/javy.rb', line 107

def repository
  @repository
end

#versionObject

Returns the value of attribute version

Returns:

  • (Object)

    the current value of version



107
108
109
# File 'ext/javy/javy.rb', line 107

def version
  @version
end

Instance Method Details

#download(target:) ⇒ Object



108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'ext/javy/javy.rb', line 108

def download(target:)
  FileUtils.mkdir_p(BIN_FOLDER)

  source_file = url.open
  validate_sha!(source_file)
  source_file.seek(0)

  Dir.chdir(File.dirname(target)) do
    File.open(File.basename(target), "wb") do |target_file|
      decompress(source_file, target_file)
    end

    File.chmod(0755, target)
  end

  true
rescue OpenURI::HTTPError
  false
end

#filenameObject



138
139
140
141
142
143
144
145
146
# File 'ext/javy/javy.rb', line 138

def filename
  format(
    "%{basename}-%{cpu}-%{os}-%{version}.gz",
    basename: basename,
    cpu: platform.cpu,
    os: platform.os,
    version: version
  )
end

#urlObject



128
129
130
131
132
133
134
135
136
# File 'ext/javy/javy.rb', line 128

def url
  URI.parse(format(
    "https://github.com/%{owner}/%{repository}/releases/download/%{version}/%{filename}",
    owner: owner,
    repository: repository,
    version: version,
    filename: filename
  ))
end