# 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, line 16
    def initialize(options = {})
      if Puppet.features.microsoft_windows?
        raise Puppet::Error, "`puppet module` actions are currently not supported on Microsoft Windows"
      end
      @options = options
    end

run(*args) click to toggle source

    # File lib/puppet/module_tool/applications/application.rb, line 10
    def self.run(*args)
      new(*args).run
    end

### Public Instance Methods

discuss(response, success, failure) click to toggle source

    # File lib/puppet/module_tool/applications/application.rb, line 27
    def discuss(response, success, failure)
      case response
      when Net::HTTPOK, Net::HTTPCreated
        Puppet.notice success
      else
        errors = PSON.parse(response.body)['error'] rescue "HTTP #{response.code}, #{response.body}"
        Puppet.warning "#{failure} (#{errors})"
      end
    end

load_modulefile!() click to toggle source

    # File lib/puppet/module_tool/applications/application.rb, line 57
    def load_modulefile!
      @metadata = nil
      metadata(true)
    end

metadata(require_modulefile = false) click to toggle source

    # File lib/puppet/module_tool/applications/application.rb, line 37
    def metadata(require_modulefile = false)
      unless @metadata
        unless @path
          raise ArgumentError, "Could not determine module path"
        end
        @metadata = Puppet::ModuleTool::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)
          Puppet::ModuleTool::ModulefileReader.evaluate(@metadata, modulefile_path)
        elsif require_modulefile
          raise ArgumentError, "No Modulefile found."
        end
      end
      @metadata
    end

parse_filename(filename) click to toggle source

    # File lib/puppet/module_tool/applications/application.rb, line 62
    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

run() click to toggle source

    # File lib/puppet/module_tool/applications/application.rb, line 23
    def run
      raise NotImplementedError, "Should be implemented in child classes."
    end