Class: ElmInstall::Installer

Inherits:
Base
  • Object
show all
Defined in:
lib/elm_install/installer.rb

Overview

Installer class

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Installer

Initializes an installer with the given options

Parameters:

  • options (Hash) (defaults to: {})

    The options



13
14
15
16
17
# File 'lib/elm_install/installer.rb', line 13

def initialize(options = {})
  @identifier = Identifier.new Dir.new(Dir.pwd), options
  @resolver = Resolver.new @identifier, options
  self
end

Instance Method Details

#initial_solve_constraintsArray

Returns the inital constraints

Returns:

  • (Array)

    Array of dependency names and constraints



55
56
57
58
59
60
61
# File 'lib/elm_install/installer.rb', line 55

def initial_solve_constraints
  @identifier.initial_dependencies.flat_map do |dependency|
    dependency.constraints.map do |constraint|
      [dependency.name, constraint]
    end
  end
end

#installObject

Installs packages

Returns:

  • nil



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/elm_install/installer.rb', line 23

def install
  puts 'Resolving packages...'
  @graph = @resolver.resolve

  puts 'Solving dependencies...'
  (Populator.new results).populate

  puts 'Packages configured successfully!'
  nil
rescue Solve::Errors::NoSolutionError => error
  Logger.arrow "No solution found: #{error}"
  Process.abort
end

#resultsArray

Returns the results of solving

Returns:

  • (Array)

    Array of dependencies



41
42
43
44
45
46
47
48
49
# File 'lib/elm_install/installer.rb', line 41

def results
  Solve
    .it!(@graph, initial_solve_constraints)
    .map do |name, version|
      dep = @resolver.dependencies[name]
      dep.version = Semverse::Version.new(version)
      dep
    end
end