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

#dirname, #name, #owner, #path, #title

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

#accept, #full_path

Constructor Details

#initialize(title, dirname, args) ⇒ Forge

Returns a new instance of Forge.



26
27
28
29
30
31
32
33
34
35
# File 'lib/r10k/module/forge.rb', line 26

def initialize(title, dirname, args)
  super
  @metadata = R10K::Module::Metadata.new(path + 'metadata.json')

  if args.is_a? String
    @expected_version = R10K::SemVer.new(args)
  elsif args.is_a? Symbol and args == :latest
    @expected_version = args
  end
end

Instance Attribute Details

#metadataObject (readonly)

Returns the value of attribute metadata.



22
23
24
# File 'lib/r10k/module/forge.rb', line 22

def 
  @metadata
end

Class Method Details

.implement?(name, args) ⇒ Boolean

Returns:

  • (Boolean)


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

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

Instance Method Details

#current_versionR10K::SemVer Also known as: version

Returns The version of the currently installed module.

Returns:

  • (R10K::SemVer)

    The version of the currently installed module



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

def current_version
  @metadata.read
  @metadata.version
end

#exist?Boolean

Returns:

  • (Boolean)


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

def exist?
  path.exist?
end

#expected_versionR10K::SemVer

Returns The expected version that the module.

Returns:



57
58
59
60
61
62
# File 'lib/r10k/module/forge.rb', line 57

def expected_version
  if @expected_version == :latest
    set_version_from_forge
  end
  @expected_version
end

#insync?Boolean

Returns:

  • (Boolean)


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

def insync?
  status == :insync
end

#propertiesObject



48
49
50
51
52
53
54
# File 'lib/r10k/module/forge.rb', line 48

def properties
  {
    :expected => expected_version,
    :actual   => current_version,
    :type     => :forge,
  }
end

#statusSymbol

Determine the status of the forge module.

Returns:

  • (Symbol)

    :absent If the directory doesn’t exist

  • (Symbol)

    :mismatched If the module is not a forge module, or isn’t the right forge module

  • (Symbol)

    :outdated If the installed module is older than expected

  • (Symbol)

    :insync If the module is in the desired state



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/r10k/module/forge.rb', line 88

def status
  if not self.exist?
    # The module is not installed
    return :absent
  elsif not @metadata.exist?
    # The directory exists but doesn't have a metadata file; it probably
    # isn't a forge module.
    return :mismatched
  end

  # The module is present and has a metadata file, read the metadata to
  # determine the state of the module.
  @metadata.read

  if not @owner == @metadata.author
    # This is a forge module but the installed module is a different author
    # than the expected author.
    return :mismatched
  end

  if expected_version && (expected_version != @metadata.version)
    return :outdated
  end

  return :insync
end

#sync(options = {}) ⇒ Object



37
38
39
40
41
42
43
44
45
46
# File 'lib/r10k/module/forge.rb', line 37

def sync(options = {})
  case status
  when :absent
    install
  when :outdated
    upgrade
  when :mismatched
    reinstall
  end
end