Class: R10K::Module::Base
- Inherits:
-
Object
- Object
- R10K::Module::Base
- Includes:
- Logging
- Defined in:
- lib/r10k/module/base.rb
Overview
This class defines a common interface for module implementations.
Direct Known Subclasses
Definition, Forge, Git, Local, SVN
Constant Summary
Constants included from Logging
Instance Attribute Summary collapse
- #dirname ⇒ Object (also: #basedir) readonly
-
#environment ⇒ Object
readonly
Returns the value of attribute environment.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#origin ⇒ String
Where the module was sourced from.
-
#owner ⇒ Object
(also: #author)
readonly
Returns the value of attribute owner.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#spec_deletable ⇒ Boolean
Set this to true if the spec dir can be safely removed, ie in the moduledir.
-
#title ⇒ Object
(also: #full_name)
readonly
Returns the value of attribute title.
Instance Method Summary collapse
-
#accept(visitor) ⇒ Object
Deprecated.
-
#cachedir ⇒ String, :none
Return the module’s cachedir.
-
#delete_spec_dir ⇒ Object
Actually remove the spec dir.
- #full_path ⇒ String deprecated Deprecated.
-
#initialize(title, dirname, args, environment = nil) ⇒ Base
constructor
A new instance of Base.
-
#maybe_delete_spec_dir ⇒ Object
Delete the spec dir if @exclude_spec has been set to true and @spec_deletable is also true.
-
#properties ⇒ Hash
abstract
Return the properties of the module.
- #should_sync? ⇒ Boolean
-
#status ⇒ Symbol
abstract
Return the status of the currently installed module.
-
#sync(opts = {}) ⇒ Boolean
Synchronize this module with the indicated state.
-
#version ⇒ Object
abstract
Return the desired version of this module.
Methods included from Logging
debug_formatter, default_formatter, default_outputter, #logger, #logger_name, parse_level
Constructor Details
#initialize(title, dirname, args, environment = nil) ⇒ Base
Returns a new instance of Base.
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/r10k/module/base.rb', line 54 def initialize(title, dirname, args, environment=nil) @title = PuppetForge::V3.normalize_name(title) @dirname = dirname @args = args @owner, @name = parse_title(@title) @path = Pathname.new(File.join(@dirname, @name)) @environment = environment @overrides = args.delete(:overrides) || {} @spec_deletable = true @exclude_spec = args.delete(:exclude_spec) @exclude_spec = @overrides[:modules].delete(:exclude_spec) if @overrides.dig(:modules, :exclude_spec) @origin = 'external' # Expect Puppetfile or R10k::Environment to set this to a specific value @requested_modules = @overrides.dig(:modules, :requested_modules) || [] @should_sync = (@requested_modules.empty? || @requested_modules.include?(@name)) end |
Instance Attribute Details
#dirname ⇒ Object (readonly) Also known as: basedir
20 21 22 |
# File 'lib/r10k/module/base.rb', line 20 def dirname @dirname end |
#environment ⇒ Object (readonly)
Returns the value of attribute environment.
35 36 37 |
# File 'lib/r10k/module/base.rb', line 35 def environment @environment end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
16 17 18 |
# File 'lib/r10k/module/base.rb', line 16 def name @name end |
#origin ⇒ String
Returns Where the module was sourced from. E.g., “Puppetfile”.
39 40 41 |
# File 'lib/r10k/module/base.rb', line 39 def origin @origin end |
#owner ⇒ Object (readonly) Also known as:
Returns the value of attribute owner.
27 28 29 |
# File 'lib/r10k/module/base.rb', line 27 def owner @owner end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
31 32 33 |
# File 'lib/r10k/module/base.rb', line 31 def path @path end |
#spec_deletable ⇒ Boolean
Returns set this to true if the spec dir can be safely removed, ie in the moduledir.
43 44 45 |
# File 'lib/r10k/module/base.rb', line 43 def spec_deletable @spec_deletable end |
#title ⇒ Object (readonly) Also known as: full_name
Returns the value of attribute title.
12 13 14 |
# File 'lib/r10k/module/base.rb', line 12 def title @title end |
Instance Method Details
#accept(visitor) ⇒ Object
Deprecated
147 148 149 |
# File 'lib/r10k/module/base.rb', line 147 def accept(visitor) visitor.visit(:module, self) end |
#cachedir ⇒ String, :none
Return the module’s cachedir. Subclasses that implement a cache will override this to return a real directory location.
163 164 165 |
# File 'lib/r10k/module/base.rb', line 163 def cachedir :none end |
#delete_spec_dir ⇒ Object
Actually remove the spec dir
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/r10k/module/base.rb', line 89 def delete_spec_dir spec_path = @path + 'spec' if spec_path.symlink? spec_path = spec_path.realpath end if spec_path.directory? logger.debug2 _("Deleting spec data at #{spec_path}") # Use the secure flag for the #rm_rf method to avoid security issues # involving TOCTTOU(time of check to time of use); more details here: # https://ruby-doc.org/stdlib-2.7.0/libdoc/fileutils/rdoc/FileUtils.html#method-c-rm_rf # Additionally, #rm_rf also has problems in windows with with symlink targets # also being deleted; this should be revisted if Windows becomes higher priority. FileUtils.rm_rf(spec_path, secure: true) else logger.debug2 _("No spec dir detected at #{spec_path}, skipping deletion") end end |
#full_path ⇒ String
Returns The full filesystem path to the module.
73 74 75 |
# File 'lib/r10k/module/base.rb', line 73 def full_path path.to_s end |
#maybe_delete_spec_dir ⇒ Object
Delete the spec dir if @exclude_spec has been set to true and @spec_deletable is also true
78 79 80 81 82 83 84 85 86 |
# File 'lib/r10k/module/base.rb', line 78 def maybe_delete_spec_dir if @exclude_spec if @spec_deletable delete_spec_dir else logger.info _("Spec dir for #{@title} will not be deleted because it is not in the moduledir") end end end |
#properties ⇒ Hash
Return the properties of the module
155 156 157 |
# File 'lib/r10k/module/base.rb', line 155 def properties raise NotImplementedError end |
#should_sync? ⇒ Boolean
114 115 116 117 118 119 120 121 122 |
# File 'lib/r10k/module/base.rb', line 114 def should_sync? if @should_sync logger.info _("Deploying module to %{path}") % {path: path} true else logger.debug1(_("Only updating modules %{modules}, skipping module %{name}") % {modules: @requested_modules.inspect, name: name}) false end end |
#status ⇒ Symbol
Return the status of the currently installed module.
This can return the following values:
* :absent - there is no module installed
* :mismatched - there is a module installed but it must be removed and reinstalled
* :outdated - the correct module is installed but it needs to be updated
* :insync - the correct module is installed and up to date, or the module is actually a boy band.
142 143 144 |
# File 'lib/r10k/module/base.rb', line 142 def status raise NotImplementedError end |
#sync(opts = {}) ⇒ Boolean
Synchronize this module with the indicated state.
110 111 112 |
# File 'lib/r10k/module/base.rb', line 110 def sync(opts={}) raise NotImplementedError end |
#version ⇒ Object
Return the desired version of this module
127 128 129 |
# File 'lib/r10k/module/base.rb', line 127 def version raise NotImplementedError end |