Class: Helpers

Inherits:
Object
  • Object
show all
Defined in:
lib/retrospec/plugins/v1/plugin/helpers.rb

Class Method Summary collapse

Class Method Details

.get_module_nameString

Returns - the name of the module.

Returns:

  • (String)
    • the name of the module



6
7
8
9
10
11
12
13
# File 'lib/retrospec/plugins/v1/plugin/helpers.rb', line 6

def self.get_module_name
  module_name = nil
  Dir['manifests/*.pp'].entries.each do |manifest|
    module_name = get_module_name_from_file(manifest)
    break unless module_name.nil?
  end
  module_name
end

.get_module_name_from_file(file) ⇒ String

Returns - the name of the module.

Parameters:

  • file (String)
    • the initial manifest file that contains the name of the module

Returns:

  • (String)
    • the name of the module



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/retrospec/plugins/v1/plugin/helpers.rb', line 17

def self.get_module_name_from_file(file)
  p = Puppet::Parser::Lexer.new
  module_name = nil
  p.string = File.read(file)
  tokens = p.fullscan

  i = tokens.index { |token| [:CLASS, :DEFINE].include? token.first }
  module_name = tokens[i + 1].last[:value].split('::').first unless i.nil?

  module_name
end

.is_module_dir?(dir) ⇒ Boolean

Returns - true if the module contains a manifests directory.

Parameters:

  • dir (String)
    • the module dir

Returns:

  • (Boolean)
    • true if the module contains a manifests directory



31
32
33
# File 'lib/retrospec/plugins/v1/plugin/helpers.rb', line 31

def self.is_module_dir?(dir)
  Dir[File.join(dir, '*')].entries.include? 'manifests'
end