Class: Puppet::ModuleTool::Applications::Application
- Inherits:
-
Object
- Object
- Puppet::ModuleTool::Applications::Application
show all
- Includes:
- Util::Colors
- Defined in:
- lib/puppet/module_tool/applications/application.rb
Constant Summary
Util::Colors::BG_BLUE, Util::Colors::BG_CYAN, Util::Colors::BG_GREEN, Util::Colors::BG_HBLUE, Util::Colors::BG_HCYAN, Util::Colors::BG_HGREEN, Util::Colors::BG_HMAGENTA, Util::Colors::BG_HRED, Util::Colors::BG_HWHITE, Util::Colors::BG_HYELLOW, Util::Colors::BG_MAGENTA, Util::Colors::BG_RED, Util::Colors::BG_WHITE, Util::Colors::BG_YELLOW, Util::Colors::BLACK, Util::Colors::BLUE, Util::Colors::CYAN, Util::Colors::Colormap, Util::Colors::GREEN, Util::Colors::HBLACK, Util::Colors::HBLUE, Util::Colors::HCYAN, Util::Colors::HGREEN, Util::Colors::HMAGENTA, Util::Colors::HRED, Util::Colors::HWHITE, Util::Colors::HYELLOW, Util::Colors::MAGENTA, Util::Colors::RED, Util::Colors::RESET, Util::Colors::WHITE, Util::Colors::YELLOW
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
#colorize, #console_color, #console_has_color?, #html_color
Constructor Details
#initialize(options = {}) ⇒ Application
Returns a new instance of Application.
17
18
19
|
# File 'lib/puppet/module_tool/applications/application.rb', line 17
def initialize(options = {})
@options = options
end
|
Instance Attribute Details
15
16
17
|
# File 'lib/puppet/module_tool/applications/application.rb', line 15
def options
@options
end
|
Class Method Details
.run(*args) ⇒ Object
11
12
13
|
# File 'lib/puppet/module_tool/applications/application.rb', line 11
def self.run(*args)
new(*args).run
end
|
Instance Method Details
#discuss(response, success, failure) ⇒ Object
25
26
27
28
29
30
31
32
33
|
# File 'lib/puppet/module_tool/applications/application.rb', line 25
def discuss(response, success, failure)
case response
when Net::HTTPOK, Net::HTTPCreated
Puppet.notice success
else
errors = JSON.parse(response.body)['error'] rescue "HTTP #{response.code}, #{response.body}"
Puppet.warning "#{failure} (#{errors})"
end
end
|
73
74
75
76
|
# File 'lib/puppet/module_tool/applications/application.rb', line 73
def load_metadata!
@metadata = nil
metadata(true)
end
|
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
# File 'lib/puppet/module_tool/applications/application.rb', line 35
def metadata(require_metadata = false)
return @metadata if @metadata
@metadata = Puppet::ModuleTool::Metadata.new
unless @path
raise ArgumentError, "Could not determine module path"
end
if require_metadata && !Puppet::ModuleTool.is_module_root?(@path)
raise ArgumentError, "Unable to find metadata.json or Modulefile in module root at #{@path} See http://links.puppetlabs.com/modulefile for required file format."
end
modulefile_path = File.join(@path, 'Modulefile')
metadata_path = File.join(@path, 'metadata.json')
if File.file?(metadata_path)
File.open(metadata_path) do |f|
begin
@metadata.update(JSON.load(f))
rescue JSON::ParserError => ex
raise ArgumentError, "Could not parse JSON #{metadata_path}", ex.backtrace
end
end
end
if File.file?(modulefile_path)
if File.file?(metadata_path)
Puppet.warning "Modulefile is deprecated. Merging your Modulefile and metadata.json."
else
Puppet.warning "Modulefile is deprecated. Building metadata.json from Modulefile."
end
Puppet::ModuleTool::ModulefileReader.evaluate(@metadata, modulefile_path)
end
return @metadata
end
|
#parse_filename(filename) ⇒ Object
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
# File 'lib/puppet/module_tool/applications/application.rb', line 78
def parse_filename(filename)
if match = /^((.*?)-(.*?))-(\d+\.\d+\.\d+.*?)$/.match(File.basename(filename,'.tar.gz'))
module_name, author, shortname, version = match.captures
else
raise ArgumentError, "Could not parse filename to obtain the username, module name and version. (#{@release_name})"
end
unless SemVer.valid?(version)
raise ArgumentError, "Invalid version format: #{version} (Semantic Versions are acceptable: http://semver.org)"
end
return {
:module_name => module_name,
:author => author,
:dir_name => shortname,
:version => version
}
end
|
21
22
23
|
# File 'lib/puppet/module_tool/applications/application.rb', line 21
def run
raise NotImplementedError, "Should be implemented in child classes."
end
|