Class: PuppetDebugger::InputResponders::Resources

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

Constant Summary collapse

COMMAND_WORDS =
%w(resources)
SUMMARY =
'List all the resources current in the catalog.'
COMMAND_GROUP =
:scope

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, #modules_paths, #puppet_debugger_lib_dir, summary

Instance Method Details

#find_resources(resources, filter = []) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/plugins/puppet-debugger/input_responders/resources.rb', line 19

def find_resources(resources, filter = [])
  return resources if filter.nil? || filter.empty?
  filter_string = filter.join(' ').downcase
  resources.find_all do |resource|
    resource.name.to_s.downcase.include?(filter_string) || resource.type.to_s.downcase.include?(filter_string)
  end
end

#run(args = []) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/plugins/puppet-debugger/input_responders/resources.rb', line 9

def run(args = [])
  filter = args
  resources = find_resources(debugger.catalog.resources, filter)
  modified = resources.map do |res|
    res.to_s.gsub(/\[/, "['").gsub(/\]/, "']") # ensure the title has quotes
  end
  output = "Resources not shown in any specific order\n".warning
  output += modified.ai
end