Class: PuppetDebugger::InputResponders::Datatypes

Inherits:
PuppetDebugger::InputResponderPlugin show all
Defined in:
lib/plugins/puppet-debugger/input_responders/datatypes.rb

Constant Summary collapse

COMMAND_WORDS =
%w(datatypes)
SUMMARY =
'List all the datatypes available in the environment.'
COMMAND_GROUP =
:environment

Instance Attribute Summary

Attributes inherited from PuppetDebugger::InputResponderPlugin

#debugger

Instance Method Summary collapse

Methods inherited from PuppetDebugger::InputResponderPlugin

command_completion, command_group, command_words, details, execute, #puppet_debugger_lib_dir, summary

Instance Method Details

#all_data_typesArray[String]

Returns - combined list of core data types and environment data types.

Returns:

  • (Array[String])
    • combined list of core data types and environment data types



32
33
34
35
36
37
38
# File 'lib/plugins/puppet-debugger/input_responders/datatypes.rb', line 32

def all_data_types
  unless loaders.respond_to?(:implementation_registry)
    Puppet.info("Data Types Not Available in Puppet: #{Puppet.version}")
    return []
  end
  core_datatypes + environment_data_types
end

#core_datatypesArray[String]

Returns - a list of core data types.

Returns:

  • (Array[String])
    • a list of core data types



25
26
27
28
29
# File 'lib/plugins/puppet-debugger/input_responders/datatypes.rb', line 25

def core_datatypes
  loaders.implementation_registry
      .instance_variable_get(:'@implementations_per_type_name')
      .keys.find_all { |t| t !~ /::/ }
end

#environment_data_typesArray[String]

Returns - returns a list of all the custom data types found in all the modules in the environment.

Returns:

  • (Array[String])
    • returns a list of all the custom data types found in all the modules in the environment



14
15
16
17
18
19
20
21
22
# File 'lib/plugins/puppet-debugger/input_responders/datatypes.rb', line 14

def environment_data_types
  globs = debugger.puppet_environment.instance_variable_get(:@modulepath).map { |m| File.join(m, '**', 'types', '**', '*.pp') }
  files = globs.map { |g| Dir.glob(g) }.flatten
  files.map do |f|
    m = File.read(f).match(/type\s([a-z\d\:_]+)/i)
    next if m =~ /type|alias/ # can't figure out the best way to filter type and alias out
    m[1] if m && m[1] =~ /::/
  end.uniq.compact
end

#run(args = []) ⇒ Object



9
10
11
# File 'lib/plugins/puppet-debugger/input_responders/datatypes.rb', line 9

def run(args = [])
  all_data_types.sort.ai
end