Sha256: 344752f65bf0eb60147db3cad212e17a3aef6d0ee0eda05774b5f9e50eac8b3c

Contents?: true

Size: 1.34 KB

Versions: 7

Compression:

Stored size: 1.34 KB

Contents

require 'puppet-debugger/input_responder_plugin'
module PuppetDebugger
  module InputResponders
    class Whereami < InputResponderPlugin
      COMMAND_WORDS = %w(whereami)
      SUMMARY = 'Show code surrounding the current context.'
      COMMAND_GROUP = :context

      # source_file and source_line_num instance variables must be set for this
      # method to show the surrounding code
      # @return [String] - string output of the code surrounded by the breakpoint or nil if file
      # or line_num do not exist
      def run(args = [])
        num_lines = parse(args.first)
        file = debugger.source_file
        line_num = debugger.source_line_num
        if file && line_num
          if file == :code
            source_code = Puppet[:code]
            code = DebuggerCode.from_string(source_code, :puppet)
          else
            code = DebuggerCode.from_file(file, :puppet)
          end
          return code.with_marker(line_num).around(line_num, num_lines)
                     .with_line_numbers.with_indentation(5).with_file_reference.to_s
        end
      end

      # @return [Integer]
      # @param num [String,Integer] number of lines
      # @param defalt [Integer] - default value to return if supplied is less than 5
      def parse(num, default = 7)
        value = num.to_i
        value >= 5 ? value : default
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
puppet-debugger-0.19.0 lib/plugins/puppet-debugger/input_responders/whereami.rb
puppet-debugger-0.18.0 lib/plugins/puppet-debugger/input_responders/whereami.rb
puppet-debugger-0.17.0 lib/plugins/puppet-debugger/input_responders/whereami.rb
puppet-debugger-0.16.0 lib/plugins/puppet-debugger/input_responders/whereami.rb
puppet-debugger-0.15.2 lib/plugins/puppet-debugger/input_responders/whereami.rb
puppet-debugger-0.15.1 lib/plugins/puppet-debugger/input_responders/whereami.rb
puppet-debugger-0.15.0 lib/plugins/puppet-debugger/input_responders/whereami.rb