Class: Enola::Resolver

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

Defined Under Namespace

Classes: Found

Constant Summary collapse

EXECUTABLE =
File.expand_path("../../exe/enola", __dir__)
MAX_SCRIPT_BYTES =

A binstub is a script; the released binary is megabytes. The cap keeps the whole-file read cheap and means a real binary is never slurped to be rejected.

64 * 1024

Instance Method Summary collapse

Constructor Details

#initialize(channel: Enola.channel, cache_root: Enola.cache_root, platform: Platform.current, path: ENV.fetch("PATH", "")) ⇒ Resolver

Returns a new instance of Resolver.



7
8
9
10
11
# File 'lib/enola/resolver.rb', line 7

def initialize(channel: Enola.channel, cache_root: Enola.cache_root, platform: Platform.current, path: ENV.fetch("PATH", ""))
  @channel = channel
  @fetcher = Fetcher.new(channel: channel, cache_root: cache_root, platform: platform)
  @path = path
end

Instance Method Details

#resolveObject



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/enola/resolver.rb', line 13

def resolve
  return Found.new(@fetcher.binary_path, "cache") if @fetcher.cached?

  on_path, found_version = matching_path_binary
  return Found.new(on_path, "path") if on_path

  begin
    Found.new(@fetcher.fetch, "fetched")
  rescue Unavailable => e
    raise Unavailable, found_version ? "#{e.message}; the enola on PATH is #{found_version}, the Gemfile pins #{@channel.version}" : e.message
  end
end