Class: R10K::Module::Forge
- Includes:
- Logging
- Defined in:
- lib/r10k/module/forge.rb
Constant Summary
Constants included from Logging
Instance Attribute Summary collapse
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#v3_module ⇒ Object
readonly
Returns the value of attribute v3_module.
Attributes inherited from Base
#dirname, #name, #owner, #path, #title
Class Method Summary collapse
Instance Method Summary collapse
-
#current_version ⇒ String
(also: #version)
The version of the currently installed module.
- #exist? ⇒ Boolean
-
#expected_version ⇒ String
The expected version that the module.
-
#initialize(title, dirname, expected_version) ⇒ Forge
constructor
A new instance of Forge.
- #install ⇒ Object (also: #upgrade)
- #insync? ⇒ Boolean
- #properties ⇒ Object
- #reinstall ⇒ Object
-
#status ⇒ Symbol
Determine the status of the forge module.
- #sync(options = {}) ⇒ Object
- #uninstall ⇒ Object
Methods included from Logging
debug_formatter, default_formatter, default_outputter, #logger, #logger_name, parse_level
Methods inherited from Base
Constructor Details
#initialize(title, dirname, expected_version) ⇒ Forge
Returns a new instance of Forge.
32 33 34 35 36 37 38 39 |
# File 'lib/r10k/module/forge.rb', line 32 def initialize(title, dirname, expected_version) super @metadata_file = R10K::Module::MetadataFile.new(path + 'metadata.json') @metadata = @metadata_file.read @expected_version = expected_version || current_version || :latest @v3_module = PuppetForge::V3::Module.new(@title) end |
Instance Attribute Details
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
23 24 25 |
# File 'lib/r10k/module/forge.rb', line 23 def @metadata end |
#v3_module ⇒ Object (readonly)
Returns the value of attribute v3_module.
28 29 30 |
# File 'lib/r10k/module/forge.rb', line 28 def v3_module @v3_module end |
Class Method Details
.implement?(name, args) ⇒ Boolean
16 17 18 |
# File 'lib/r10k/module/forge.rb', line 16 def self.implement?(name, args) !!(name.match %r[\w+[/-]\w+]) end |
Instance Method Details
#current_version ⇒ String Also known as: version
Returns The version of the currently installed module.
69 70 71 |
# File 'lib/r10k/module/forge.rb', line 69 def current_version @metadata ? @metadata.version : nil end |
#exist? ⇒ Boolean
75 76 77 |
# File 'lib/r10k/module/forge.rb', line 75 def exist? path.exist? end |
#expected_version ⇒ String
Returns The expected version that the module.
61 62 63 64 65 66 |
# File 'lib/r10k/module/forge.rb', line 61 def expected_version if @expected_version == :latest @expected_version = @v3_module.latest_version end @expected_version end |
#install ⇒ Object Also known as: upgrade
118 119 120 121 122 123 124 125 |
# File 'lib/r10k/module/forge.rb', line 118 def install parent_path = @path.parent if !parent_path.exist? parent_path.mkpath end module_release = R10K::Forge::ModuleRelease.new(@title, expected_version) module_release.install(@path) end |
#insync? ⇒ Boolean
79 80 81 |
# File 'lib/r10k/module/forge.rb', line 79 def insync? status == :insync end |
#properties ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/r10k/module/forge.rb', line 52 def properties { :expected => expected_version, :actual => current_version, :type => :forge, } end |
#reinstall ⇒ Object
133 134 135 136 |
# File 'lib/r10k/module/forge.rb', line 133 def reinstall uninstall install end |
#status ⇒ Symbol
Determine the status of the forge module.
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/r10k/module/forge.rb', line 90 def status if not self.exist? # The module is not installed return :absent elsif not File.exist?(@path + 'metadata.json') # 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_file.read(@path + 'metadata.json') if not @title.tr('/','-') == @metadata.full_module_name.tr('/','-') # 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
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/r10k/module/forge.rb', line 41 def sync( = {}) case status when :absent install when :outdated upgrade when :mismatched reinstall end end |
#uninstall ⇒ Object
129 130 131 |
# File 'lib/r10k/module/forge.rb', line 129 def uninstall FileUtils.rm_rf full_path end |