Class: Puppet::Module::Tool::Applications::Application

Inherits:
Object
  • Object
show all
Includes:
Utils::Interrogation
Defined in:
lib/puppet/module/tool/applications/application.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Utils::Interrogation

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

Constructor Details

#initialize(options = {}) ⇒ Application

Returns a new instance of Application.



15
16
17
18
# File 'lib/puppet/module/tool/applications/application.rb', line 15

def initialize(options = {})
  @options = options
  Puppet::Module::Tool.prepare_settings(options)
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



13
14
15
# File 'lib/puppet/module/tool/applications/application.rb', line 13

def options
  @options
end

Class Method Details

.run(*args) ⇒ Object



9
10
11
# File 'lib/puppet/module/tool/applications/application.rb', line 9

def self.run(*args)
  new(*args).run
end

Instance Method Details

#discuss(response, success, failure) ⇒ Object



28
29
30
31
32
33
34
35
36
# File 'lib/puppet/module/tool/applications/application.rb', line 28

def discuss(response, success, failure)
  case response
  when Net::HTTPOK, Net::HTTPCreated
    say success
  else
    errors = PSON.parse(response.body)['error'] rescue "HTTP #{response.code}, #{response.body}"
    say "#{failure} (#{errors})"
  end
end

#load_modulefile!Object



58
59
60
61
# File 'lib/puppet/module/tool/applications/application.rb', line 58

def load_modulefile!
  @metadata = nil
  (true)
end

#metadata(require_modulefile = false) ⇒ Object



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

def (require_modulefile = false)
  unless @metadata
    unless @path
      abort "Could not determine module path"
    end
    @metadata = Metadata.new
    contents = ContentsDescription.new(@path)
    contents.annotate(@metadata)
    checksums = Checksums.new(@path)
    checksums.annotate(@metadata)
    modulefile_path = File.join(@path, 'Modulefile')
    if File.file?(modulefile_path)
      Modulefile.evaluate(@metadata, modulefile_path)
    elsif require_modulefile
      abort "No Modulefile found."
    end
  end
  @metadata
end

#parse_filename!Object

Use to extract and validate a module name and version from a filename Note: Must have @filename set to use this



66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/puppet/module/tool/applications/application.rb', line 66

def parse_filename!
  @release_name = File.basename(@filename,'.tar.gz')
  @username, @module_name, @version = @release_name.split('-', 3)
  @full_name = [@username, @module_name].join('-')
  unless @username && @module_name
    abort "Username and Module name not provided"
  end
  begin
    Gem::Version.new(@version)
  rescue ArgumentError => e
    abort "Invalid version format: #{@version}"
  end
end

#repositoryObject



20
21
22
# File 'lib/puppet/module/tool/applications/application.rb', line 20

def repository
  @repository ||= Repository.new(Puppet.settings[:puppet_module_repository])
end

#runObject

Raises:

  • (NotImplementedError)


24
25
26
# File 'lib/puppet/module/tool/applications/application.rb', line 24

def run
  raise NotImplementedError, "Should be implemented in child classes."
end