Class: Bolt::Module

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

Constant Summary collapse

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.



26
27
28
29
# File 'lib/bolt/module.rb', line 26

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

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#pathObject (readonly)

Returns the value of attribute path.



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

def path
  @path
end

Class Method Details

.discover(modulepath) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/bolt/module.rb', line 8

def self.discover(modulepath)
  modulepath.each_with_object({}) do |path, mods|
    next unless File.exist?(path) && File.directory?(path)
    (Dir.entries(path) - %w[. ..])
      .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
end

Instance Method Details

#plugin?Boolean

Returns:

  • (Boolean)


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

def plugin?
  File.exist?(plugin_data_file)
end

#plugin_data_fileObject



31
32
33
# File 'lib/bolt/module.rb', line 31

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