Class: Bolt::Module

Inherits:
Object
  • Object
show all
Defined in:
lib/bolt/module.rb

Constant Summary collapse

CONTENT_NAME_REGEX =
/\A[a-z][a-z0-9_]*(::[a-z][a-z0-9_]*)*\z/.freeze
MODULE_NAME_REGEX =
/\A[a-z][a-z0-9_]*\z/.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, path) ⇒ Module

Returns a new instance of Module.



35
36
37
38
# File 'lib/bolt/module.rb', line 35

def initialize(name, path)
  @name = name
  @path = path
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



33
34
35
# File 'lib/bolt/module.rb', line 33

def name
  @name
end

#pathObject (readonly)

Returns the value of attribute path.



33
34
35
# File 'lib/bolt/module.rb', line 33

def path
  @path
end

Class Method Details

.discover(modulepath, project) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/bolt/module.rb', line 9

def self.discover(modulepath, project)
  mods = {}

  if project.load_as_module?
    mods[project.name] = Bolt::Module.new(project.name, project.path.to_s)
  end

  modulepath.each do |path|
    next unless File.exist?(path) && File.directory?(path)
    Dir.children(path)
       .map { |dir| File.join(path, dir) }
       .select { |dir| File.directory?(dir) }
       .each do |dir|
      module_name = File.basename(dir)
      if module_name =~ MODULE_NAME_REGEX
        # Puppet will load some objects from shadowed modules but this won't
        mods[module_name] ||= Bolt::Module.new(module_name, dir)
      end
    end
  end

  mods
end

Instance Method Details

#plugin?Boolean

Returns:

  • (Boolean)


44
45
46
47
48
49
50
51
52
# File 'lib/bolt/module.rb', line 44

def plugin?
  if File.exist?(File.join(path, 'bolt-plugin.json'))
    msg = "Found bolt-plugin.json in module #{name} at #{path}. Bolt looks for " \
      "bolt_plugin.json to determine if the module contains plugins. " \
      "Rename the file for Bolt to recognize it."
    Bolt::Logger.warn_once('plugin_file_name', msg)
  end
  File.exist?(plugin_data_file)
end

#plugin_data_fileObject



40
41
42
# File 'lib/bolt/module.rb', line 40

def plugin_data_file
  File.join(path, 'bolt_plugin.json')
end