Class: PuppetDebugger::InputResponders::Playbooks
- Inherits:
-
InputResponderPlugin
- Object
- InputResponderPlugin
- PuppetDebugger::InputResponders::Playbooks
- Defined in:
- lib/plugins/puppet-debugger/input_responders/playbooks.rb
Constant Summary collapse
- COMMAND_WORDS =
%w(playbooks)
- SUMMARY =
'Show a list of available playbooks.'- COMMAND_GROUP =
:editing
Class Method Summary collapse
- .command_completion(buffer_words) ⇒ Object
- .directories ⇒ Object
-
.external_directory ⇒ Array[String]
empty array is returned if no external directory.
-
.gemspecs ⇒ Object
Returns an Array of Gem::Specification objects.
-
.internal_directories ⇒ String
-
the path to the playbooks directory.
-
-
.playbooks_dir_list ⇒ Array[String]
-
a list of puppet debugger playbook directories.
-
Instance Method Summary collapse
Class Method Details
.command_completion(buffer_words) ⇒ Object
9 10 11 12 13 14 15 16 17 |
# File 'lib/plugins/puppet-debugger/input_responders/playbooks.rb', line 9 def self.command_completion(buffer_words) directories.map do |d| path = File.join(d, *buffer_words) glob_path = File.directory?(path) ? File.join(path, '*') : path + '*' files = Dir.glob(glob_path) dirs = files.grep(path).map { |f| File.basename(f, File.extname(f)) } files.find_all {|d| d.match(path) }.map { |f| File.basename(f, File.extname(f)) } - dirs end.flatten.sort end |
.directories ⇒ Object
19 20 21 |
# File 'lib/plugins/puppet-debugger/input_responders/playbooks.rb', line 19 def self.directories (internal_directories + external_directory).uniq end |
.external_directory ⇒ Array[String]
empty array is returned if no external directory
30 31 32 |
# File 'lib/plugins/puppet-debugger/input_responders/playbooks.rb', line 30 def self.external_directory [ENV['PLAYBOOKS_DIR']].compact end |
.gemspecs ⇒ Object
Returns an Array of Gem::Specification objects.
45 46 47 48 |
# File 'lib/plugins/puppet-debugger/input_responders/playbooks.rb', line 45 def self.gemspecs @gemspecs ||= Gem::Specification.respond_to?(:latest_specs) ? Gem::Specification.latest_specs : Gem.searcher.init_gemspecs end |
.internal_directories ⇒ String
Returns - the path to the playbooks directory.
24 25 26 |
# File 'lib/plugins/puppet-debugger/input_responders/playbooks.rb', line 24 def self.internal_directories playbooks_dir_list end |
.playbooks_dir_list ⇒ Array[String]
Returns - a list of puppet debugger playbook directories.
35 36 37 38 39 40 41 42 |
# File 'lib/plugins/puppet-debugger/input_responders/playbooks.rb', line 35 def self.playbooks_dir_list @playbooks_dir_list ||= begin gemspecs.collect do |spec| lib_path = File.join(spec.full_gem_path,'lib','puppet-debugger','playbooks') lib_path if Dir.exist?(lib_path) end.compact end end |
Instance Method Details
#create_tree(dirs = []) ⇒ Object
77 78 79 80 81 82 83 84 85 |
# File 'lib/plugins/puppet-debugger/input_responders/playbooks.rb', line 77 def create_tree(dirs = []) tree = [] dirs.each do |dir| walk(dir) do |path, depth| tree << sprintf("%s%s\n", (' ' * depth), File.basename(path, File.extname(path)) ) end end tree.join() end |
#playbook_file(words) ⇒ Object
50 51 52 53 54 55 56 57 58 |
# File 'lib/plugins/puppet-debugger/input_responders/playbooks.rb', line 50 def playbook_file(words) path = File.join(*words) file = nil self.class.directories.find do |dir| search_path = File.join(dir, path) + '*' file = Dir.glob(search_path).find {|f| File.file?(f)} end file end |
#run(args = []) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/plugins/puppet-debugger/input_responders/playbooks.rb', line 60 def run(args = []) if args.count > 0 file = playbook_file(args) return debugger.handle_input("play #{file}") if file && File.exist?(file) self.class.directories.each do |dir| walk(dir) do |path| if args.first == File.basename(path) return create_tree([path]) end end end else create_tree(self.class.directories) end end |