Class: Puppet::Moddeps::InstallDeps
- Inherits:
-
Object
- Object
- Puppet::Moddeps::InstallDeps
- Defined in:
- lib/puppet/moddeps/install_deps.rb
Instance Attribute Summary collapse
-
#deps ⇒ Object
readonly
Returns the value of attribute deps.
-
#module_path ⇒ Object
readonly
Returns the value of attribute module_path.
Instance Method Summary collapse
- #help ⇒ Object
-
#initialize(path = nil, deps = nil) ⇒ InstallDeps
constructor
A new instance of InstallDeps.
- #install(*puppet_module) ⇒ Object
- #install_modules ⇒ Object
- #installed?(module_name) ⇒ Boolean
- #parse_deps(data) ⇒ Object
- #parse_metadata(module_name) ⇒ Object
- #path_separator(os_string) ⇒ Object
Constructor Details
#initialize(path = nil, deps = nil) ⇒ InstallDeps
Returns a new instance of InstallDeps.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/puppet/moddeps/install_deps.rb', line 11 def initialize(path=nil, deps=nil) if path and path.is_a?(String) @module_path = path elsif path abort('The provided path was not a string.') else separator = self.path_separator(RbConfig::CONFIG['host_os']) @module_path = %x(puppet config print modulepath).split(separator)[0] end if deps and deps.is_a?(Array) @deps = deps elsif deps abort('The provided dependency list was not an array.') else @deps = [] end end |
Instance Attribute Details
#deps ⇒ Object (readonly)
Returns the value of attribute deps.
9 10 11 |
# File 'lib/puppet/moddeps/install_deps.rb', line 9 def deps @deps end |
#module_path ⇒ Object (readonly)
Returns the value of attribute module_path.
9 10 11 |
# File 'lib/puppet/moddeps/install_deps.rb', line 9 def module_path @module_path end |
Instance Method Details
#help ⇒ Object
50 51 52 53 |
# File 'lib/puppet/moddeps/install_deps.rb', line 50 def help puts 'Usage: puppet-moddeps module' puts ' Call puppet-moddeps with the name of one installed module' end |
#install(*puppet_module) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/puppet/moddeps/install_deps.rb', line 30 def install(*puppet_module) if puppet_module.size >=1 and puppet_module[0].is_a?(Array) args = puppet_module[0] else args = puppet_module end if args.size == 1 if installed?(args[0]) self.(args[0]) self.install_modules else puts "Can't find #{args[0]} in #{@module_path}" end else self.help end end |
#install_modules ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/puppet/moddeps/install_deps.rb', line 82 def install_modules if @deps.size > 0 puts "Modules will be installed into #{module_path}" @deps.each do |dep| if self.installed?(dep) puts "#{dep} is already installed, skipping." else cmd = "puppet module install #{dep}" puts "Running \"#{cmd}\"..." %x(#{cmd}) end end else puts 'No dependencies were marked for installation.' end end |
#installed?(module_name) ⇒ Boolean
55 56 57 |
# File 'lib/puppet/moddeps/install_deps.rb', line 55 def installed?(module_name) File.directory?("#{@module_path}/#{module_name}") end |
#parse_deps(data) ⇒ Object
73 74 75 76 77 78 79 80 |
# File 'lib/puppet/moddeps/install_deps.rb', line 73 def parse_deps(data) @deps.clear data['dependencies'].each do |dep| depname = dep["name"].sub '/', '-' @deps.push( depname ) end end |
#parse_metadata(module_name) ⇒ Object
67 68 69 70 71 |
# File 'lib/puppet/moddeps/install_deps.rb', line 67 def (module_name) = File.read("#{@module_path}/#{module_name}/metadata.json") data = JSON.parse() self.parse_deps(data) end |
#path_separator(os_string) ⇒ Object
59 60 61 62 63 64 65 |
# File 'lib/puppet/moddeps/install_deps.rb', line 59 def path_separator(os_string) if (/cygwin|mswin|mingw|bccwin|wince|emx/ =~ os_string) != nil separator = ';' else separator = ':' end end |