Class: Puppet::ModuleTool::Applications::Application

Inherits:
Object
  • Object
show all
Includes:
Util::Colors
Defined in:
lib/vendor/puppet/module_tool/applications/application.rb

Direct Known Subclasses

Checksummer, Uninstaller

Constant Summary

Constants included from Util::Colors

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

Methods included from Util::Colors

#colorize, #console_color, #console_has_color?, #html_color

Constructor Details

#initialize(options = {}) ⇒ Application

Returns a new instance of Application.



16
17
18
19
20
21
# File 'lib/vendor/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

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



14
15
16
# File 'lib/vendor/puppet/module_tool/applications/application.rb', line 14

def options
  @options
end

Class Method Details

.run(*args) ⇒ Object



10
11
12
# File 'lib/vendor/puppet/module_tool/applications/application.rb', line 10

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

Instance Method Details

#discuss(response, success, failure) ⇒ Object



27
28
29
30
31
32
33
34
35
# File 'lib/vendor/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!Object



57
58
59
60
# File 'lib/vendor/puppet/module_tool/applications/application.rb', line 57

def load_modulefile!
  @metadata = nil
  (true)
end

#metadata(require_modulefile = false) ⇒ Object



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

def (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) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/vendor/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

#runObject

Raises:

  • (NotImplementedError)


23
24
25
# File 'lib/vendor/puppet/module_tool/applications/application.rb', line 23

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