Class: Puppet::Module::Tool::Applications::Installer

Inherits:
Application
  • Object
show all
Defined in:
lib/puppet/module/tool/applications/installer.rb

Instance Attribute Summary

Attributes inherited from Application

#options

Instance Method Summary collapse

Methods inherited from Application

#discuss, #load_modulefile!, #metadata, #parse_filename!, #repository, run

Methods included from Utils::Interrogation

#confirms?, #header, #prompt, #say, #subheader

Constructor Details

#initialize(name, options = {}) ⇒ Installer

Returns a new instance of Installer.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/puppet/module/tool/applications/installer.rb', line 11

def initialize(name, options = {})
  if File.exist?(name)
    if File.directory?(name)
      # TODO Unify this handling with that of Unpacker#check_clobber!
      abort "Module already installed: #{name}"
    end
    @source = :filesystem
    @filename = File.expand_path(name)
    parse_filename!
  else
    @source = :repository
    begin
      @username, @module_name = Puppet::Module::Tool::username_and_modname_from(name)
    rescue ArgumentError
      abort "Could not install module with invalid name: #{name}"
    end
    @version_requirement = options[:version]
  end
  super(options)
end

Instance Method Details

#force?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/puppet/module/tool/applications/installer.rb', line 32

def force?
  options[:force]
end

#runObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/puppet/module/tool/applications/installer.rb', line 36

def run
  case @source
  when :repository
    if match['file']
      begin
        cache_path = repository.retrieve(match['file'])
      rescue OpenURI::HTTPError => e
        abort "Could not install module: #{e.message}"
      end
      Unpacker.run(cache_path, Dir.pwd, options)
    else
      abort "Malformed response from module repository."
    end
  when :filesystem
    repository = Repository.new('file:///')
    uri = URI.parse("file://#{File.expand_path(@filename)}")
    cache_path = repository.retrieve(uri)
    Unpacker.run(cache_path, Dir.pwd, options)
  else
    abort "Could not determine installation source"
  end
end