Class: ShopifyExtensions::Asset

Inherits:
Struct
  • Object
show all
Defined in:
ext/shopify-extensions/shopify_extensions.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



68
69
70
# File 'ext/shopify-extensions/shopify_extensions.rb', line 68

def basename
  @basename
end

#ownerObject

Returns the value of attribute owner

Returns:

  • (Object)

    the current value of owner



68
69
70
# File 'ext/shopify-extensions/shopify_extensions.rb', line 68

def owner
  @owner
end

#platformObject

Returns the value of attribute platform

Returns:

  • (Object)

    the current value of platform



68
69
70
# File 'ext/shopify-extensions/shopify_extensions.rb', line 68

def platform
  @platform
end

#repositoryObject

Returns the value of attribute repository

Returns:

  • (Object)

    the current value of repository



68
69
70
# File 'ext/shopify-extensions/shopify_extensions.rb', line 68

def repository
  @repository
end

#versionObject

Returns the value of attribute version

Returns:

  • (Object)

    the current value of version



68
69
70
# File 'ext/shopify-extensions/shopify_extensions.rb', line 68

def version
  @version
end

Instance Method Details

#download(target:) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
# File 'ext/shopify-extensions/shopify_extensions.rb', line 69

def download(target:)
  Dir.chdir(File.dirname(target)) do
    File.open(File.basename(target), "wb") do |target_file|
      decompress(url.open, target_file)
    end
    File.chmod(0755, target)
  end

  true
rescue OpenURI::HTTPError
  false
end

#filenameObject



92
93
94
95
96
97
98
99
100
# File 'ext/shopify-extensions/shopify_extensions.rb', line 92

def filename
  format(
    "%{basename}-%{os}-%{cpu}.%{extension}",
    basename: basename,
    os: platform.os,
    cpu: platform.cpu,
    extension: platform.os == "windows" ? "exe.gz" : "gz"
  )
end

#urlObject



82
83
84
85
86
87
88
89
90
# File 'ext/shopify-extensions/shopify_extensions.rb', line 82

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