Class: R10K::Module::Forge

Inherits:
Base
  • Object
show all
Includes:
Logging
Defined in:
lib/r10k/module/forge.rb

Constant Summary

Constants included from Logging

Logging::LOG_LEVELS

Instance Attribute Summary collapse

Attributes inherited from Base

#basedir, #name

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Logging

formatter, included, level, level=, levels, #logger, #logger_name, outputter, parse_level

Methods inherited from Base

#full_path

Constructor Details

#initialize(name, basedir, args) ⇒ Forge

Returns a new instance of Forge.



22
23
24
25
26
27
28
29
30
31
# File 'lib/r10k/module/forge.rb', line 22

def initialize(name, basedir, args)
  @full_name = name
  @basedir   = basedir

  @owner, @name = name.split('/')

  if args.is_a? String
    @version = R10K::SemVer.new(args)
  end
end

Instance Attribute Details

#full_nameObject

Returns the value of attribute full_name.



20
21
22
# File 'lib/r10k/module/forge.rb', line 20

def full_name
  @full_name
end

#ownerObject

Returns the value of attribute owner.



20
21
22
# File 'lib/r10k/module/forge.rb', line 20

def owner
  @owner
end

Class Method Details

.implement?(name, args) ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/r10k/module/forge.rb', line 14

def self.implement?(name, args)
  !!(name.match %r[\w+/\w+])
end

Instance Method Details

#insync?Boolean

Returns:

  • (Boolean)


74
75
76
# File 'lib/r10k/module/forge.rb', line 74

def insync?
  @version == version
end

#metadataObject



78
79
80
# File 'lib/r10k/module/forge.rb', line 78

def 
  @metadata = JSON.parse(File.read()) rescue nil
end

#metadata_pathObject



82
83
84
# File 'lib/r10k/module/forge.rb', line 82

def 
  File.join(full_path, 'metadata.json')
end

#sync(options = {}) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/r10k/module/forge.rb', line 33

def sync(options = {})
  return if insync?

  if insync?
    #logger.debug1 "Module #{@full_name} already matches version #{@version}"
  elsif File.exist? 
    #logger.debug "Module #{@full_name} is installed but doesn't match version #{@version}, upgrading"

    # A Pulp based puppetforge http://www.pulpproject.org/ wont support
    # `puppet module install abc/xyz --version=v1.5.9` but puppetlabs forge
    # will support `puppet module install abc/xyz --version=1.5.9`
    #
    # Removing v from the semver for constructing the command ensures
    # compatibility across both
    cmd = []
    cmd << 'upgrade'
    cmd << "--version=#{@version.to_s.sub(/^v/,'')}" if @version
    cmd << "--ignore-dependencies"
    cmd << @full_name
    pmt cmd
  else
    FileUtils.mkdir @basedir unless File.directory? @basedir
    #logger.debug "Module #{@full_name} is not installed"
    cmd = []
    cmd << 'install'
    cmd << "--version=#{@version.to_s.sub(/^v/,'')}" if @version
    cmd << "--ignore-dependencies"
    cmd << @full_name
    pmt cmd
  end
end

#versionR10K::SemVer, NilClass

Returns:



66
67
68
69
70
71
72
# File 'lib/r10k/module/forge.rb', line 66

def version
  if 
    R10K::SemVer.new(['version'])
  else
    R10K::SemVer::MIN
  end
end