Class: Bolt::ModuleInstaller::Specs

Inherits:
Object
  • Object
show all
Defined in:
lib/bolt/module_installer/specs.rb,
lib/bolt/module_installer/specs/git_spec.rb,
lib/bolt/module_installer/specs/forge_spec.rb

Defined Under Namespace

Classes: ForgeSpec, GitSpec

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(specs = []) ⇒ Specs

Returns a new instance of Specs.



10
11
12
13
14
# File 'lib/bolt/module_installer/specs.rb', line 10

def initialize(specs = [])
  @specs = []
  add_specs(specs)
  assert_unique_names
end

Class Method Details

.from_puppetfile(puppetfile) ⇒ Object

Creates a list of specs from the modules in a Puppetfile object.



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

def self.from_puppetfile(puppetfile)
  new(puppetfile.modules.map(&:to_hash))
end

Instance Method Details

#add_specs(*specs) ⇒ Object

Adds a spec.



37
38
39
40
41
42
43
44
45
46
# File 'lib/bolt/module_installer/specs.rb', line 37

def add_specs(*specs)
  specs.flatten.map do |spec|
    case spec
    when Hash
      @specs.unshift spec_from_hash(spec)
    else
      @specs.unshift spec
    end
  end
end

#include?(name) ⇒ Boolean

Returns true if the specs includes the given name.

Returns:

  • (Boolean)


30
31
32
33
# File 'lib/bolt/module_installer/specs.rb', line 30

def include?(name)
  _owner, name = name.tr('-', '/').split('/', 2)
  @specs.any? { |spec| spec.name == name }
end

#satisfied_by?(puppetfile) ⇒ Boolean

Returns true if all specs are satisfied by the modules in a Puppetfile.

Returns:

  • (Boolean)


64
65
66
67
68
69
70
# File 'lib/bolt/module_installer/specs.rb', line 64

def satisfied_by?(puppetfile)
  @specs.all? do |spec|
    puppetfile.modules.any? do |mod|
      spec.satisfied_by?(mod)
    end
  end
end

#specsObject

Returns a list of specs.



24
25
26
# File 'lib/bolt/module_installer/specs.rb', line 24

def specs
  @specs.uniq(&:name)
end