Class: Enola::Fetcher
- Inherits:
-
Object
- Object
- Enola::Fetcher
- Defined in:
- lib/enola/fetcher.rb
Constant Summary collapse
- REDIRECTS =
5
Instance Method Summary collapse
- #binary_path ⇒ Object
- #cached? ⇒ Boolean
- #fetch ⇒ Object
-
#initialize(channel: Enola.channel, cache_root: Enola.cache_root, platform: Platform.current) ⇒ Fetcher
constructor
A new instance of Fetcher.
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_path ⇒ Object
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
24 25 26 |
# File 'lib/enola/fetcher.rb', line 24 def cached? File.executable?(binary_path) end |
#fetch ⇒ Object
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 |