Class: Gembrew::Resolver

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cache_root: nil, reporter: Reporter.new, command_runner: nil, archive_store: nil, github_archive_store: nil) ⇒ Resolver

Returns a new instance of Resolver.



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/gembrew/resolver.rb', line 19

def initialize(cache_root: nil, reporter: Reporter.new, command_runner: nil, archive_store: nil,
               github_archive_store: nil)
  @cache_root = Pathname(cache_root || default_cache_root)
  @reporter = reporter
  @command_runner = command_runner || method(:run_command)
  @archive_store = archive_store || ArchiveStore.new(
    cache_path: @cache_root/'gems', reporter: reporter, command_runner: @command_runner
  )
  @github_archive_store = github_archive_store
  temporary_root.mkpath
end

Instance Attribute Details

#cache_rootObject (readonly)

Returns the value of attribute cache_root.



17
18
19
# File 'lib/gembrew/resolver.rb', line 17

def cache_root
  @cache_root
end

Instance Method Details

#resolve(name, version, source:) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/gembrew/resolver.rb', line 31

def resolve(name, version, source:)
  Dir.mktmpdir('build-', temporary_root.to_s) do |directory|
    temporary = Pathname(directory)
    root_archive, root_spec = root_source name, version, source, temporary
    dependencies = dependency_specs(lock(root_spec, temporary), root_spec)

    reporter.collecting dependencies.length
    resources = dependencies.each_with_index.map do |spec, index|
      resource spec, temporary, index + 1, dependencies.length
    end

    Resolution.new(root_spec, Digest::SHA256.file(root_archive).hexdigest, resources)
  end
end