Class: Bolt::ModuleInstaller::Specs::ForgeSpec
- Inherits:
-
Object
- Object
- Bolt::ModuleInstaller::Specs::ForgeSpec
- 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
-
#full_name ⇒ Object
readonly
Returns the value of attribute full_name.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#resolve ⇒ Object
readonly
Returns the value of attribute resolve.
-
#semantic_version ⇒ Object
readonly
Returns the value of attribute semantic_version.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#version_requirement ⇒ Object
readonly
Returns the value of attribute version_requirement.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(init_hash) ⇒ ForgeSpec
constructor
A new instance of ForgeSpec.
-
#satisfied_by?(mod) ⇒ Boolean
Returns true if the specification is satisfied by the module.
-
#to_hash ⇒ Object
Returns a hash matching the module spec in bolt-project.yaml.
-
#to_resolver_module ⇒ Object
Creates a PuppetfileResolver::Puppetfile::ForgeModule object, which is used to generate a graph of resolved modules.
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_name ⇒ Object (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 |
#name ⇒ Object (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 |
#resolve ⇒ Object (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_version ⇒ Object (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 |
#type ⇒ Object (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_requirement ⇒ Object (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
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.
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_hash ⇒ Object
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_module ⇒ Object
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 |