Class: ElmInstall::Installer

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/elm_install/installer.rb

Overview

This class is responsible getting a solution for the ‘elm-package.json` file and populating the `elm-stuff` directory with the packages and writing the `elm-stuff/exact-dependencies.json`.

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Installer

Initializes a new installer with the given options.



15
16
17
18
19
20
21
# File 'lib/elm_install/installer.rb', line 15

def initialize(options)
  init_options options
  @git_resolver = GitResolver.new directory: cache_directory
  @cache = Cache.new directory: cache_directory
  @populator = Populator.new @git_resolver
  @options = options
end

Instance Method Details

#cache_directoryObject



28
29
30
# File 'lib/elm_install/installer.rb', line 28

def cache_directory
  @options[:cache_directory]
end

#init_options(options = { verbose: false }) ⇒ Object



23
24
25
26
# File 'lib/elm_install/installer.rb', line 23

def init_options(options = { verbose: false })
  options[:cache_directory] ||= File.join(Dir.home, '.elm-install')
  @options = options
end

#installObject

Executes the installation

:reek:TooManyStatements { max_statements: 7 }



35
36
37
38
39
40
41
42
43
# File 'lib/elm_install/installer.rb', line 35

def install
  puts 'Resolving packages...'
  resolver.add_constraints dependencies

  puts 'Solving dependencies...'
  populate_elm_stuff
rescue
  retry_install
end

#retry_installObject



51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/elm_install/installer.rb', line 51

def retry_install
  Logger.arrow(
    'Could not find a solution in local cache, refreshing packages...'
  )

  @git_resolver.clear
  resolver.add_constraints dependencies

  populate_elm_stuff
rescue Solve::Errors::NoSolutionError => error
  puts 'Could not find a solution:'
  puts error.to_s.indent(2)
end

#saveObject



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

def save
  puts 'Saving package cache...'
  @git_resolver.save
  @cache.save
end