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