Class: Bolt::ModuleInstaller::Specs::ForgeSpec

Inherits:
Object
  • Object
show all
Defined in:
lib/bolt/module_installer/specs/forge_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[name]).freeze
KNOWN_KEYS =
Set.new(%w[name resolve version_requirement]).freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(init_hash) ⇒ ForgeSpec

Returns a new instance of ForgeSpec.



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/bolt/module_installer/specs/forge_spec.rb', line 20

def initialize(init_hash)
  @resolve                                = init_hash.key?('resolve') ? init_hash['resolve'] : true
  @full_name, @name                       = parse_name(init_hash['name'])
  @version_requirement, @semantic_version = parse_version_requirement(init_hash['version_requirement'])
  @type                                   = :forge

  unless @resolve == true || @resolve == false
    raise Bolt::ValidationError,
          "Option 'resolve' for module spec #{@full_name} must be a Boolean"
  end
end

Instance Attribute Details

#full_nameObject (readonly)

Returns the value of attribute full_name.



18
19
20
# File 'lib/bolt/module_installer/specs/forge_spec.rb', line 18

def full_name
  @full_name
end

#nameObject (readonly)

Returns the value of attribute name.



18
19
20
# File 'lib/bolt/module_installer/specs/forge_spec.rb', line 18

def name
  @name
end

#resolveObject (readonly)

Returns the value of attribute resolve.



18
19
20
# File 'lib/bolt/module_installer/specs/forge_spec.rb', line 18

def resolve
  @resolve
end

#semantic_versionObject (readonly)

Returns the value of attribute semantic_version.



18
19
20
# File 'lib/bolt/module_installer/specs/forge_spec.rb', line 18

def semantic_version
  @semantic_version
end

#typeObject (readonly)

Returns the value of attribute type.



18
19
20
# File 'lib/bolt/module_installer/specs/forge_spec.rb', line 18

def type
  @type
end

#version_requirementObject (readonly)

Returns the value of attribute version_requirement.



18
19
20
# File 'lib/bolt/module_installer/specs/forge_spec.rb', line 18

def version_requirement
  @version_requirement
end

Class Method Details

.implements?(hash) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/bolt/module_installer/specs/forge_spec.rb', line 32

def self.implements?(hash)
  KNOWN_KEYS.superset?(hash.keys.to_set) && REQUIRED_KEYS.subset?(hash.keys.to_set)
end

Instance Method Details

#satisfied_by?(mod) ⇒ Boolean

Returns true if the specification is satisfied by the module.

Returns:

  • (Boolean)


62
63
64
65
66
67
# File 'lib/bolt/module_installer/specs/forge_spec.rb', line 62

def satisfied_by?(mod)
  @type == mod.type &&
    @full_name.downcase == mod.full_name.downcase &&
    !mod.version.nil? &&
    @semantic_version.cover?(mod.version)
end

#to_hashObject

Returns a hash matching the module spec in bolt-project.yaml



71
72
73
74
75
76
# File 'lib/bolt/module_installer/specs/forge_spec.rb', line 71

def to_hash
  {
    'name'                => @full_name,
    'version_requirement' => @version_requirement
  }.compact
end

#to_resolver_moduleObject

Creates a PuppetfileResolver::Puppetfile::ForgeModule object, which is used to generate a graph of resolved modules.



81
82
83
84
85
86
87
# File 'lib/bolt/module_installer/specs/forge_spec.rb', line 81

def to_resolver_module
  require 'puppetfile-resolver'

  PuppetfileResolver::Puppetfile::ForgeModule.new(@full_name).tap do |mod|
    mod.version = @version_requirement
  end
end