Class: Bolt::ModuleInstaller::Specs::GitSpec
- Inherits:
-
Object
- Object
- Bolt::ModuleInstaller::Specs::GitSpec
- Defined in:
- lib/bolt/module_installer/specs/git_spec.rb
Constant Summary collapse
- NAME_REGEX =
%r{\A(?:[a-zA-Z0-9]+[-/])?(?<name>[a-z][a-z0-9_]*)\z}.freeze
- REQUIRED_KEYS =
Set.new(%w[git ref]).freeze
- KNOWN_KEYS =
Set.new(%w[git name ref resolve]).freeze
Instance Attribute Summary collapse
-
#git ⇒ Object
readonly
Returns the value of attribute git.
-
#ref ⇒ Object
readonly
Returns the value of attribute ref.
-
#resolve ⇒ Object
readonly
Returns the value of attribute resolve.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(init_hash, config = {}) ⇒ GitSpec
constructor
A new instance of GitSpec.
-
#name ⇒ Object
Returns the module’s name.
-
#satisfied_by?(mod) ⇒ Boolean
Returns true if the specification is satisfied by the module.
-
#sha ⇒ Object
Returns the SHA for the module’s ref.
-
#to_hash ⇒ Object
Returns a hash matching the module spec in bolt-project.yaml.
-
#to_resolver_module ⇒ Object
Returns a PuppetfileResolver::Model::GitModule object for resolving.
Constructor Details
#initialize(init_hash, config = {}) ⇒ GitSpec
Returns a new instance of GitSpec.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/bolt/module_installer/specs/git_spec.rb', line 26 def initialize(init_hash, config = {}) @logger = Bolt::Logger.logger(self) @resolve = init_hash.key?('resolve') ? init_hash['resolve'] : true @git = init_hash['git'] @ref = init_hash['ref'] @name = parse_name(init_hash['name']) @proxy = config.dig('proxy') @type = :git unless @resolve == true || @resolve == false raise Bolt::ValidationError, "Option 'resolve' for module spec #{@git} must be a Boolean" end if @name.nil? && @resolve == false raise Bolt::ValidationError, "Missing name for Git module specification: #{@git}. Git module specifications "\ "must include a 'name' key when 'resolve' is false." end unless valid_url?(@git) raise Bolt::ValidationError, "Invalid URI #{@git}. Valid URIs must begin with 'git@', 'http://', 'https://' or 'ssh://'." end end |
Instance Attribute Details
#git ⇒ Object (readonly)
Returns the value of attribute git.
24 25 26 |
# File 'lib/bolt/module_installer/specs/git_spec.rb', line 24 def git @git end |
#ref ⇒ Object (readonly)
Returns the value of attribute ref.
24 25 26 |
# File 'lib/bolt/module_installer/specs/git_spec.rb', line 24 def ref @ref end |
#resolve ⇒ Object (readonly)
Returns the value of attribute resolve.
24 25 26 |
# File 'lib/bolt/module_installer/specs/git_spec.rb', line 24 def resolve @resolve end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
24 25 26 |
# File 'lib/bolt/module_installer/specs/git_spec.rb', line 24 def type @type end |
Class Method Details
.implements?(hash) ⇒ Boolean
52 53 54 |
# File 'lib/bolt/module_installer/specs/git_spec.rb', line 52 def self.implements?(hash) KNOWN_KEYS.superset?(hash.keys.to_set) && REQUIRED_KEYS.subset?(hash.keys.to_set) end |
Instance Method Details
#name ⇒ Object
Returns the module’s name.
101 102 103 |
# File 'lib/bolt/module_installer/specs/git_spec.rb', line 101 def name @name ||= parse_name(id.name) end |
#satisfied_by?(mod) ⇒ Boolean
Returns true if the specification is satisfied by the module.
75 76 77 |
# File 'lib/bolt/module_installer/specs/git_spec.rb', line 75 def satisfied_by?(mod) @type == mod.type && @git == mod.git end |
#sha ⇒ Object
Returns the SHA for the module’s ref.
107 108 109 |
# File 'lib/bolt/module_installer/specs/git_spec.rb', line 107 def sha id.sha end |
#to_hash ⇒ Object
Returns a hash matching the module spec in bolt-project.yaml
81 82 83 84 85 86 |
# File 'lib/bolt/module_installer/specs/git_spec.rb', line 81 def to_hash { 'git' => @git, 'ref' => @ref } end |
#to_resolver_module ⇒ Object
Returns a PuppetfileResolver::Model::GitModule object for resolving.
90 91 92 93 94 95 96 97 |
# File 'lib/bolt/module_installer/specs/git_spec.rb', line 90 def to_resolver_module require 'puppetfile-resolver' PuppetfileResolver::Puppetfile::GitModule.new(name).tap do |mod| mod.remote = @git mod.ref = sha end end |