Class: Bolt::ModuleInstaller::Specs::GitSpec

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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://', or 'https://'."
  end
end

Instance Attribute Details

#gitObject (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

#refObject (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

#resolveObject (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

#typeObject (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

Returns:

  • (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

#nameObject

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.

Returns:

  • (Boolean)


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

#shaObject

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_hashObject

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_moduleObject

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