Class: ElmInstall::Installer

Inherits:
Object
  • Object
show all
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.

Parameters:

  • options (Hash)

    The 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_directoryString

Returns the path to the cache directory

Returns:

  • (String)

    The path



36
37
38
# File 'lib/elm_install/installer.rb', line 36

def cache_directory
  @options[:cache_directory]
end

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

Initializes the options setting default values.

Parameters:

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

    The options

Returns:

  • (Hash)

    The options



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

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

#installvoid

This method returns an undefined value.

Executes the installation

:reek:TooManyStatements { max_statements: 7 }



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

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

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

#retry_installvoid

This method returns an undefined value.

Clears the reference cache and retries installation.



67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/elm_install/installer.rb', line 67

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

#savevoid

This method returns an undefined value.

Saves the caches



58
59
60
61
62
# File 'lib/elm_install/installer.rb', line 58

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