Class: Enola::Fetcher

Inherits:
Object
  • Object
show all
Defined in:
lib/enola/fetcher.rb

Constant Summary collapse

REDIRECTS =
5

Instance Method Summary collapse

Constructor Details

#initialize(channel: Enola.channel, cache_root: Enola.cache_root, platform: Platform.current) ⇒ Fetcher

Returns a new instance of Fetcher.



14
15
16
17
18
# File 'lib/enola/fetcher.rb', line 14

def initialize(channel: Enola.channel, cache_root: Enola.cache_root, platform: Platform.current)
  @channel = channel
  @cache_root = cache_root
  @platform = platform
end

Instance Method Details

#binary_pathObject



20
21
22
# File 'lib/enola/fetcher.rb', line 20

def binary_path
  File.join(@channel.cache_dir(@cache_root), Platform.windows?(@platform) ? "enola.exe" : "enola")
end

#cached?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/enola/fetcher.rb', line 24

def cached?
  File.executable?(binary_path)
end

#fetchObject



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/enola/fetcher.rb', line 28

def fetch
  return binary_path if cached?

  Dir.mktmpdir("enola-fetch") do |work|
    asset = @channel.asset(@platform)
    tarball = File.join(work, asset)
    write(@channel.url(asset), tarball)
    verify(tarball, read(@channel.url(@channel.checksum_asset(@platform))), asset)
    unpack(tarball, work)
  end
  binary_path
end