class Puppet::ModuleTool::Applications::Application
Attributes
options[RW]
Public Class Methods
new(options = {})
click to toggle source
# File lib/puppet/module_tool/applications/application.rb 17 def initialize(options = {}) 18 @options = options 19 end
run(*args)
click to toggle source
# File lib/puppet/module_tool/applications/application.rb 11 def self.run(*args) 12 new(*args).run 13 end
Public Instance Methods
discuss(response, success, failure)
click to toggle source
# File lib/puppet/module_tool/applications/application.rb 25 def discuss(response, success, failure) 26 case response 27 when Net::HTTPOK, Net::HTTPCreated 28 Puppet.notice success 29 else 30 errors = Puppet::Util::Json.load(response.body)['error'] rescue "HTTP #{response.code}, #{response.body}" 31 Puppet.warning "#{failure} (#{errors})" 32 end 33 end
load_metadata!()
click to toggle source
# File lib/puppet/module_tool/applications/application.rb 66 def load_metadata! 67 @metadata = nil 68 metadata(true) 69 end
metadata(require_metadata = false)
click to toggle source
# File lib/puppet/module_tool/applications/application.rb 35 def metadata(require_metadata = false) 36 return @metadata if @metadata 37 @metadata = Puppet::ModuleTool::Metadata.new 38 39 unless @path 40 raise ArgumentError, _("Could not determine module path") 41 end 42 43 if require_metadata && !Puppet::ModuleTool.is_module_root?(@path) 44 raise ArgumentError, _("Unable to find metadata.json in module root at %{path} See https://puppet.com/docs/puppet/latest/modules_publishing.html for required file format.") % { path: @path } 45 end 46 47 metadata_path = File.join(@path, 'metadata.json') 48 49 if File.file?(metadata_path) 50 File.open(metadata_path) do |f| 51 begin 52 @metadata.update(Puppet::Util::Json.load(f)) 53 rescue Puppet::Util::Json::ParseError => ex 54 raise ArgumentError, _("Could not parse JSON %{metadata_path}") % { metadata_path: metadata_path }, ex.backtrace 55 end 56 end 57 end 58 59 if File.file?(File.join(@path, 'Modulefile')) 60 Puppet.warning _("A Modulefile was found in the root directory of the module. This file will be ignored and can safely be removed.") 61 end 62 63 return @metadata 64 end
parse_filename(filename)
click to toggle source
# File lib/puppet/module_tool/applications/application.rb 71 def parse_filename(filename) 72 match = /^((.*?)-(.*?))-(\d+\.\d+\.\d+.*?)$/.match(File.basename(filename, '.tar.gz')) 73 if match 74 module_name, author, shortname, version = match.captures 75 else 76 raise ArgumentError, _("Could not parse filename to obtain the username, module name and version. (%{release_name})") % { release_name: @release_name } 77 end 78 79 unless SemanticPuppet::Version.valid?(version) 80 raise ArgumentError, _("Invalid version format: %{version} (Semantic Versions are acceptable: http://semver.org)") % { version: version } 81 end 82 83 return { 84 :module_name => module_name, 85 :author => author, 86 :dir_name => shortname, 87 :version => version 88 } 89 end
run()
click to toggle source
# File lib/puppet/module_tool/applications/application.rb 21 def run 22 raise NotImplementedError, "Should be implemented in child classes." 23 end