Class: PuppetX::Rustup::Provider::Collection::Targets

Inherits:
Subresources
  • Object
show all
Defined in:
lib/puppet_x/rustup/provider/collection/targets.rb

Overview

A target subresource collection

Instance Method Summary collapse

Instance Method Details

#install(subresource) ⇒ Object

Install a target



40
41
42
43
44
# File 'lib/puppet_x/rustup/provider/collection/targets.rb', line 40

def install(subresource)
  @provider.rustup 'target', 'install',
    *toolchain_option(subresource['toolchain']),
    subresource['normalized_name'] || subresource['name']
end

#list_installed(toolchain) ⇒ Object

Get list of installed targets for a toolchain



32
33
34
35
36
37
# File 'lib/puppet_x/rustup/provider/collection/targets.rb', line 32

def list_installed(toolchain)
  @provider
    .rustup('target', 'list', '--installed', *toolchain_option(toolchain))
    .lines(chomp: true)
    .reject { |line| line.start_with? 'error: ' }
end

#loadObject

Get targets installed on the system.



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/puppet_x/rustup/provider/collection/targets.rb', line 9

def load
  @system = @provider.toolchains.system.reduce([]) do |combined, info|
    toolchain_name = info['name']
    combined + list_installed(toolchain_name).map do |target_name|
      {
        'ensure' => 'present',
        'name' => target_name,
        'toolchain' => toolchain_name,
      }
    end
  end
end

#normalize(target) ⇒ Object

Normalize target name.



23
24
25
26
27
28
29
# File 'lib/puppet_x/rustup/provider/collection/targets.rb', line 23

def normalize(target)
  if target == 'default'
    @provider.default_target
  else
    target
  end
end

#toolchain_option(toolchain) ⇒ Object

Generate –toolchain option to pass to rustup function



54
55
56
57
58
59
60
# File 'lib/puppet_x/rustup/provider/collection/targets.rb', line 54

def toolchain_option(toolchain)
  if toolchain
    ['--toolchain', toolchain]
  else
    []
  end
end

#uninstall(subresource) ⇒ Object

Uninstall a target



47
48
49
50
51
# File 'lib/puppet_x/rustup/provider/collection/targets.rb', line 47

def uninstall(subresource)
  @provider.rustup 'target', 'uninstall',
    *toolchain_option(subresource['toolchain']),
    subresource['normalized_name'] || subresource['name']
end