puts_debuggerer 0.8.2 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/CHANGELOG.md +63 -0
 - data/LICENSE.txt +1 -1
 - data/README.md +84 -23
 - data/VERSION +1 -1
 - data/lib/puts_debuggerer.rb +100 -24
 - metadata +4 -2
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: f418876a84bf9553ec518205bad58db7b3abc120f1cd9fcff49e6edd49267247
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 808081fdf435cd30c4d1bb1f6a4f6211068e2ae2d52c039e3f99bbbf77071744
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 4e85ad239c06a374f8e8319649cca570af59aae4b828b64e2d4e9e1102af8a41123f8896da3ce8e2ec103d5300c4968493063419a258ed672ee82de05358e3f4
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 2c56e41a7649d11ca7998d86b1682d2b16e59ecf70b94ef71c3672857c03693932d9ef797218fb65c9cfea7563c0df6428bf2e48a1ca4ac2366f38677b6bdfb8
         
     | 
    
        data/CHANGELOG.md
    ADDED
    
    | 
         @@ -0,0 +1,63 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # Change Log
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            ## 0.9.0
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
            - Provide partial support for Opal Ruby (missing display of file name, line number, and source code)
         
     | 
| 
      
 6 
     | 
    
         
            +
            - `source_line_count` option
         
     | 
| 
      
 7 
     | 
    
         
            +
            - `wraper` option for including both `header` and `footer`
         
     | 
| 
      
 8 
     | 
    
         
            +
            - Special handling of exceptions (prints using full_message)
         
     | 
| 
      
 9 
     | 
    
         
            +
            - Change :ap printer default to :p when unavailable
         
     | 
| 
      
 10 
     | 
    
         
            +
            - Support varargs printing (example: `pd arg1, arg2, arg3`)
         
     | 
| 
      
 11 
     | 
    
         
            +
            - Display `run_at` run number in printout
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
            ## 0.8.2
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
            - require 'stringio' for projects that don't require automatically via other gems
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
            ## 0.8.1
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
      
 19 
     | 
    
         
            +
            - `printer` option support for Rails test environment
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
            ## 0.8.0
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
      
 23 
     | 
    
         
            +
            - `printer` option support
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
            ## 0.7.1
         
     | 
| 
      
 26 
     | 
    
         
            +
             
     | 
| 
      
 27 
     | 
    
         
            +
            - default print engine to :ap (AwesomePrint)
         
     | 
| 
      
 28 
     | 
    
         
            +
             
     | 
| 
      
 29 
     | 
    
         
            +
            ## 0.7.0
         
     | 
| 
      
 30 
     | 
    
         
            +
             
     | 
| 
      
 31 
     | 
    
         
            +
            - `run_at` option, global and piecemeal.
         
     | 
| 
      
 32 
     | 
    
         
            +
             
     | 
| 
      
 33 
     | 
    
         
            +
            ## 0.6.1
         
     | 
| 
      
 34 
     | 
    
         
            +
             
     | 
| 
      
 35 
     | 
    
         
            +
            - updated README and broke apart specs
         
     | 
| 
      
 36 
     | 
    
         
            +
             
     | 
| 
      
 37 
     | 
    
         
            +
            ## 0.6.0
         
     | 
| 
      
 38 
     | 
    
         
            +
             
     | 
| 
      
 39 
     | 
    
         
            +
            - unofficial erb support, returning evaluated object/expression, removed static syntax support (replaced with header support)
         
     | 
| 
      
 40 
     | 
    
         
            +
             
     | 
| 
      
 41 
     | 
    
         
            +
            ## 0.5.1
         
     | 
| 
      
 42 
     | 
    
         
            +
             
     | 
| 
      
 43 
     | 
    
         
            +
            - support for print engine lambdas and smart defaults for leveraging Rails and AwesomePrint debuggers in Rails
         
     | 
| 
      
 44 
     | 
    
         
            +
             
     | 
| 
      
 45 
     | 
    
         
            +
            ## 0.5.0
         
     | 
| 
      
 46 
     | 
    
         
            +
             
     | 
| 
      
 47 
     | 
    
         
            +
            - custom formatter, caller backtrace, per-puts piecemeal options, and multi-line support
         
     | 
| 
      
 48 
     | 
    
         
            +
             
     | 
| 
      
 49 
     | 
    
         
            +
            ## 0.4.0
         
     | 
| 
      
 50 
     | 
    
         
            +
             
     | 
| 
      
 51 
     | 
    
         
            +
            - custom print engine (e.g. ap), custom announcer, and IRB support
         
     | 
| 
      
 52 
     | 
    
         
            +
             
     | 
| 
      
 53 
     | 
    
         
            +
            ## 0.3.0
         
     | 
| 
      
 54 
     | 
    
         
            +
             
     | 
| 
      
 55 
     | 
    
         
            +
            - header/footer support, multi-line printout, improved format
         
     | 
| 
      
 56 
     | 
    
         
            +
             
     | 
| 
      
 57 
     | 
    
         
            +
            ## 0.2.0
         
     | 
| 
      
 58 
     | 
    
         
            +
             
     | 
| 
      
 59 
     | 
    
         
            +
            - App path exclusion support, Rails root support, improved format
         
     | 
| 
      
 60 
     | 
    
         
            +
             
     | 
| 
      
 61 
     | 
    
         
            +
            ## 0.1.0
         
     | 
| 
      
 62 
     | 
    
         
            +
             
     | 
| 
      
 63 
     | 
    
         
            +
            - File/line/expression print out
         
     | 
    
        data/LICENSE.txt
    CHANGED
    
    
    
        data/README.md
    CHANGED
    
    | 
         @@ -130,7 +130,7 @@ pd order_details 
     | 
|
| 
       130 
130 
     | 
    
         
             
            Add the following to bundler's `Gemfile`.
         
     | 
| 
       131 
131 
     | 
    
         | 
| 
       132 
132 
     | 
    
         
             
            ```ruby
         
     | 
| 
       133 
     | 
    
         
            -
            gem 'puts_debuggerer', '~> 0. 
     | 
| 
      
 133 
     | 
    
         
            +
            gem 'puts_debuggerer', '~> 0.9.0'
         
     | 
| 
       134 
134 
     | 
    
         
             
            ```
         
     | 
| 
       135 
135 
     | 
    
         | 
| 
       136 
136 
     | 
    
         
             
            This is the recommended way for [Rails](rubyonrails.org) apps. Optionally, you may create an initializer under `config/initializers` named `puts_debuggerer_options.rb` to enable further customizations as per the [Options](#options) section below.
         
     | 
| 
         @@ -140,7 +140,7 @@ This is the recommended way for [Rails](rubyonrails.org) apps. Optionally, you m 
     | 
|
| 
       140 
140 
     | 
    
         
             
            Or manually install and require library.
         
     | 
| 
       141 
141 
     | 
    
         | 
| 
       142 
142 
     | 
    
         
             
            ```bash
         
     | 
| 
       143 
     | 
    
         
            -
            gem install puts_debuggerer -v0. 
     | 
| 
      
 143 
     | 
    
         
            +
            gem install puts_debuggerer -v0.9.0
         
     | 
| 
       144 
144 
     | 
    
         
             
            ```
         
     | 
| 
       145 
145 
     | 
    
         | 
| 
       146 
146 
     | 
    
         
             
            ```ruby
         
     | 
| 
         @@ -331,6 +331,68 @@ Prints out: 
     | 
|
| 
       331 
331 
     | 
    
         
             
            ********************************************************************************
         
     | 
| 
       332 
332 
     | 
    
         
             
            ```
         
     | 
| 
       333 
333 
     | 
    
         | 
| 
      
 334 
     | 
    
         
            +
            #### `PutsDebuggerer.wrapper`
         
     | 
| 
      
 335 
     | 
    
         
            +
            (default = `'*'*80`)
         
     | 
| 
      
 336 
     | 
    
         
            +
             
     | 
| 
      
 337 
     | 
    
         
            +
            Wrapper to include at the top and bottom of every print out (both header and footer).
         
     | 
| 
      
 338 
     | 
    
         
            +
            * Default value is `nil`
         
     | 
| 
      
 339 
     | 
    
         
            +
            * Value `true` enables wrapper as `'*'*80`
         
     | 
| 
      
 340 
     | 
    
         
            +
            * Value `false`, `nil`, or empty string disables wrapper
         
     | 
| 
      
 341 
     | 
    
         
            +
            * Any other string value gets set as a custom wrapper
         
     | 
| 
      
 342 
     | 
    
         
            +
             
     | 
| 
      
 343 
     | 
    
         
            +
            Example:
         
     | 
| 
      
 344 
     | 
    
         
            +
             
     | 
| 
      
 345 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 346 
     | 
    
         
            +
            PutsDebuggerer.wrapper = true
         
     | 
| 
      
 347 
     | 
    
         
            +
            pd (x=1)
         
     | 
| 
      
 348 
     | 
    
         
            +
            ```
         
     | 
| 
      
 349 
     | 
    
         
            +
             
     | 
| 
      
 350 
     | 
    
         
            +
            Prints out:
         
     | 
| 
      
 351 
     | 
    
         
            +
             
     | 
| 
      
 352 
     | 
    
         
            +
            ```bash
         
     | 
| 
      
 353 
     | 
    
         
            +
            ********************************************************************************
         
     | 
| 
      
 354 
     | 
    
         
            +
            [PD] /Users/User/example.rb:2
         
     | 
| 
      
 355 
     | 
    
         
            +
               > pd x=1
         
     | 
| 
      
 356 
     | 
    
         
            +
              => "1"
         
     | 
| 
      
 357 
     | 
    
         
            +
            ********************************************************************************
         
     | 
| 
      
 358 
     | 
    
         
            +
            ```
         
     | 
| 
      
 359 
     | 
    
         
            +
             
     | 
| 
      
 360 
     | 
    
         
            +
            #### `PutsDebuggerer.source_line_count`
         
     | 
| 
      
 361 
     | 
    
         
            +
            (default = `1`)
         
     | 
| 
      
 362 
     | 
    
         
            +
             
     | 
| 
      
 363 
     | 
    
         
            +
            Example:
         
     | 
| 
      
 364 
     | 
    
         
            +
             
     | 
| 
      
 365 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 366 
     | 
    
         
            +
            pd (true ||
         
     | 
| 
      
 367 
     | 
    
         
            +
              false), source_line_count: 2
         
     | 
| 
      
 368 
     | 
    
         
            +
            ```
         
     | 
| 
      
 369 
     | 
    
         
            +
             
     | 
| 
      
 370 
     | 
    
         
            +
            Prints out:
         
     | 
| 
      
 371 
     | 
    
         
            +
             
     | 
| 
      
 372 
     | 
    
         
            +
            ```
         
     | 
| 
      
 373 
     | 
    
         
            +
            [PD] /Users/User/example.rb:2
         
     | 
| 
      
 374 
     | 
    
         
            +
               > pd (true ||
         
     | 
| 
      
 375 
     | 
    
         
            +
                   false), source_line_count: 2
         
     | 
| 
      
 376 
     | 
    
         
            +
              => "true"
         
     | 
| 
      
 377 
     | 
    
         
            +
            ```
         
     | 
| 
      
 378 
     | 
    
         
            +
             
     | 
| 
      
 379 
     | 
    
         
            +
            Example:
         
     | 
| 
      
 380 
     | 
    
         
            +
             
     | 
| 
      
 381 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 382 
     | 
    
         
            +
            PutsDebuggerer.source_line_count = 2 # setting via global option
         
     | 
| 
      
 383 
     | 
    
         
            +
            pd (true ||
         
     | 
| 
      
 384 
     | 
    
         
            +
              false)
         
     | 
| 
      
 385 
     | 
    
         
            +
            ```
         
     | 
| 
      
 386 
     | 
    
         
            +
             
     | 
| 
      
 387 
     | 
    
         
            +
            Prints out:
         
     | 
| 
      
 388 
     | 
    
         
            +
             
     | 
| 
      
 389 
     | 
    
         
            +
            ```
         
     | 
| 
      
 390 
     | 
    
         
            +
            [PD] /Users/User/example.rb:2
         
     | 
| 
      
 391 
     | 
    
         
            +
               > pd (true ||
         
     | 
| 
      
 392 
     | 
    
         
            +
                   false), source_line_count: 2
         
     | 
| 
      
 393 
     | 
    
         
            +
              => "true"
         
     | 
| 
      
 394 
     | 
    
         
            +
            ```
         
     | 
| 
      
 395 
     | 
    
         
            +
             
     | 
| 
       334 
396 
     | 
    
         
             
            #### `PutsDebuggerer.printer`
         
     | 
| 
       335 
397 
     | 
    
         
             
            (default = `:puts`)
         
     | 
| 
       336 
398 
     | 
    
         | 
| 
         @@ -608,28 +670,26 @@ puts __caller_source_line__ 
     | 
|
| 
       608 
670 
     | 
    
         | 
| 
       609 
671 
     | 
    
         
             
            Prints out `puts __caller_source_line__`
         
     | 
| 
       610 
672 
     | 
    
         | 
| 
       611 
     | 
    
         
            -
            ##  
     | 
| 
       612 
     | 
    
         
            -
             
     | 
| 
       613 
     | 
    
         
            -
             
     | 
| 
       614 
     | 
    
         
            -
             
     | 
| 
       615 
     | 
    
         
            -
             
     | 
| 
       616 
     | 
    
         
            -
             
     | 
| 
       617 
     | 
    
         
            -
             
     | 
| 
       618 
     | 
    
         
            -
             
     | 
| 
       619 
     | 
    
         
            -
             
     | 
| 
       620 
     | 
    
         
            -
             
     | 
| 
       621 
     | 
    
         
            -
             
     | 
| 
       622 
     | 
    
         
            -
             
     | 
| 
       623 
     | 
    
         
            -
             
     | 
| 
       624 
     | 
    
         
            -
             
     | 
| 
       625 
     | 
    
         
            -
             
     | 
| 
      
 673 
     | 
    
         
            +
            ## Compatibility
         
     | 
| 
      
 674 
     | 
    
         
            +
             
     | 
| 
      
 675 
     | 
    
         
            +
            [puts_debuggerer](https://rubygems.org/gems/puts_debuggerer) is fully compatible with: 
         
     | 
| 
      
 676 
     | 
    
         
            +
            - [Ruby](https://www.ruby-lang.org/en/)
         
     | 
| 
      
 677 
     | 
    
         
            +
            - [JRuby](https://www.jruby.org/)
         
     | 
| 
      
 678 
     | 
    
         
            +
            - IRB
         
     | 
| 
      
 679 
     | 
    
         
            +
            - Rails Console.
         
     | 
| 
      
 680 
     | 
    
         
            +
             
     | 
| 
      
 681 
     | 
    
         
            +
            It has partial-compatibility with [Opal Ruby](https://opalrb.com/) with everything working except these features:
         
     | 
| 
      
 682 
     | 
    
         
            +
            - File name display
         
     | 
| 
      
 683 
     | 
    
         
            +
            - Line number display
         
     | 
| 
      
 684 
     | 
    
         
            +
            - Source code call display
         
     | 
| 
      
 685 
     | 
    
         
            +
             
     | 
| 
      
 686 
     | 
    
         
            +
            ## Change Log
         
     | 
| 
      
 687 
     | 
    
         
            +
             
     | 
| 
      
 688 
     | 
    
         
            +
            [CHANGELOG.md](CHANGELOG.md)
         
     | 
| 
       626 
689 
     | 
    
         | 
| 
       627 
690 
     | 
    
         
             
            ## TODO
         
     | 
| 
       628 
691 
     | 
    
         | 
| 
       629 
     | 
    
         
            -
             
     | 
| 
       630 
     | 
    
         
            -
            * fix issue with erb support
         
     | 
| 
       631 
     | 
    
         
            -
            * display run_at run number in printout
         
     | 
| 
       632 
     | 
    
         
            -
            * implement fallback in irb for when line number cannot be discovered (issue happens in pry, perhaps this just means support pry)
         
     | 
| 
      
 692 
     | 
    
         
            +
            [TODO.md](TODO)
         
     | 
| 
       633 
693 
     | 
    
         | 
| 
       634 
694 
     | 
    
         
             
            ## Contributing
         
     | 
| 
       635 
695 
     | 
    
         | 
| 
         @@ -645,5 +705,6 @@ Prints out `puts __caller_source_line__` 
     | 
|
| 
       645 
705 
     | 
    
         | 
| 
       646 
706 
     | 
    
         
             
            ## Copyright
         
     | 
| 
       647 
707 
     | 
    
         | 
| 
       648 
     | 
    
         
            -
             
     | 
| 
       649 
     | 
    
         
            -
             
     | 
| 
      
 708 
     | 
    
         
            +
            [MIT](LICENSE.txt)
         
     | 
| 
      
 709 
     | 
    
         
            +
             
     | 
| 
      
 710 
     | 
    
         
            +
            Copyright (c) 2017-2020 - Andy Maleh.
         
     | 
    
        data/VERSION
    CHANGED
    
    | 
         @@ -1 +1 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            0. 
     | 
| 
      
 1 
     | 
    
         
            +
            0.9.0
         
     | 
    
        data/lib/puts_debuggerer.rb
    CHANGED
    
    | 
         @@ -1,9 +1,10 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require ' 
     | 
| 
       2 
     | 
    
         
            -
            require 'awesome_print'
         
     | 
| 
      
 1 
     | 
    
         
            +
            require 'awesome_print' unless RUBY_PLATFORM == 'opal'
         
     | 
| 
       3 
2 
     | 
    
         
             
            require 'stringio'
         
     | 
| 
       4 
3 
     | 
    
         | 
| 
       5 
4 
     | 
    
         
             
            module PutsDebuggerer
         
     | 
| 
      
 5 
     | 
    
         
            +
              SOURCE_LINE_COUNT_DEFAULT = 1
         
     | 
| 
       6 
6 
     | 
    
         
             
              HEADER_DEFAULT = '*'*80
         
     | 
| 
      
 7 
     | 
    
         
            +
              WRAPPER_DEFAULT = '*'*80
         
     | 
| 
       7 
8 
     | 
    
         
             
              FOOTER_DEFAULT = '*'*80
         
     | 
| 
       8 
9 
     | 
    
         
             
              PRINTER_DEFAULT = :puts
         
     | 
| 
       9 
10 
     | 
    
         
             
              PRINTER_RAILS = lambda do |output|
         
     | 
| 
         @@ -15,11 +16,13 @@ module PutsDebuggerer 
     | 
|
| 
       15 
16 
     | 
    
         
             
              PRINT_ENGINE_MESSAGE_INVALID = 'print_engine must be a valid global method symbol (e.g. :p, :ap or :pp) or lambda/proc receiving an object arg'
         
     | 
| 
       16 
17 
     | 
    
         
             
              ANNOUNCER_DEFAULT = '[PD]'
         
     | 
| 
       17 
18 
     | 
    
         
             
              FORMATTER_DEFAULT = -> (data) {
         
     | 
| 
      
 19 
     | 
    
         
            +
                  puts data[:wrapper] if data[:wrapper]
         
     | 
| 
       18 
20 
     | 
    
         
             
                  puts data[:header] if data[:header]
         
     | 
| 
       19 
     | 
    
         
            -
                  print "#{data[:announcer]} #{data[:file]}:#{data[:line_number]}#{__format_pd_expression__(data[:pd_expression], data[:object])} "
         
     | 
| 
      
 21 
     | 
    
         
            +
                  print "#{data[:announcer]} #{data[:file]}:#{data[:line_number]}#{" (run:#{data[:run_number]})" if data[:run_number]}#{__format_pd_expression__(data[:pd_expression], data[:object])} "
         
     | 
| 
       20 
22 
     | 
    
         
             
                  data[:object_printer].call
         
     | 
| 
       21 
23 
     | 
    
         
             
                  puts data[:caller].map {|l| '     ' + l} unless data[:caller].to_a.empty?
         
     | 
| 
       22 
24 
     | 
    
         
             
                  puts data[:footer] if data[:footer]
         
     | 
| 
      
 25 
     | 
    
         
            +
                  puts data[:wrapper] if data[:wrapper]
         
     | 
| 
       23 
26 
     | 
    
         
             
                }
         
     | 
| 
       24 
27 
     | 
    
         
             
              CALLER_DEPTH_ZERO = 4 #depth includes pd + with_options method + nested block + build_pd_data method
         
     | 
| 
       25 
28 
     | 
    
         
             
              OBJECT_RUN_AT = {}
         
     | 
| 
         @@ -46,6 +49,28 @@ module PutsDebuggerer 
     | 
|
| 
       46 
49 
     | 
    
         
             
                  @app_path = (path || Rails.root.to_s) rescue nil
         
     | 
| 
       47 
50 
     | 
    
         
             
                end
         
     | 
| 
       48 
51 
     | 
    
         | 
| 
      
 52 
     | 
    
         
            +
                # Source Line Count.
         
     | 
| 
      
 53 
     | 
    
         
            +
                # * Default value is `1`
         
     | 
| 
      
 54 
     | 
    
         
            +
                #
         
     | 
| 
      
 55 
     | 
    
         
            +
                # Example:
         
     | 
| 
      
 56 
     | 
    
         
            +
                #
         
     | 
| 
      
 57 
     | 
    
         
            +
                #   PutsDebuggerer.source_line_count = 2
         
     | 
| 
      
 58 
     | 
    
         
            +
                #   pd (true ||
         
     | 
| 
      
 59 
     | 
    
         
            +
                #     false), source_line_count: 2
         
     | 
| 
      
 60 
     | 
    
         
            +
                #
         
     | 
| 
      
 61 
     | 
    
         
            +
                # Prints out:
         
     | 
| 
      
 62 
     | 
    
         
            +
                #
         
     | 
| 
      
 63 
     | 
    
         
            +
                #   ********************************************************************************
         
     | 
| 
      
 64 
     | 
    
         
            +
                #   [PD] /Users/User/example.rb:2
         
     | 
| 
      
 65 
     | 
    
         
            +
                #      > pd (true ||
         
     | 
| 
      
 66 
     | 
    
         
            +
                #          false), source_line_count: 2
         
     | 
| 
      
 67 
     | 
    
         
            +
                #     => "true"
         
     | 
| 
      
 68 
     | 
    
         
            +
                attr_reader :source_line_count
         
     | 
| 
      
 69 
     | 
    
         
            +
             
     | 
| 
      
 70 
     | 
    
         
            +
                def source_line_count=(value)
         
     | 
| 
      
 71 
     | 
    
         
            +
                  @source_line_count = value || SOURCE_LINE_COUNT_DEFAULT
         
     | 
| 
      
 72 
     | 
    
         
            +
                end
         
     | 
| 
      
 73 
     | 
    
         
            +
             
     | 
| 
       49 
74 
     | 
    
         
             
                # Header to include at the top of every print out.
         
     | 
| 
       50 
75 
     | 
    
         
             
                # * Default value is `nil`
         
     | 
| 
       51 
76 
     | 
    
         
             
                # * Value `true` enables header as `'*'*80`
         
     | 
| 
         @@ -79,6 +104,39 @@ module PutsDebuggerer 
     | 
|
| 
       79 
104 
     | 
    
         
             
                  !!@header
         
     | 
| 
       80 
105 
     | 
    
         
             
                end
         
     | 
| 
       81 
106 
     | 
    
         | 
| 
      
 107 
     | 
    
         
            +
                # Wrapper to include at the top and bottom of every print out (both header and footer).
         
     | 
| 
      
 108 
     | 
    
         
            +
                # * Default value is `nil`
         
     | 
| 
      
 109 
     | 
    
         
            +
                # * Value `true` enables wrapper as `'*'*80`
         
     | 
| 
      
 110 
     | 
    
         
            +
                # * Value `false`, `nil`, or empty string disables wrapper
         
     | 
| 
      
 111 
     | 
    
         
            +
                # * Any other string value gets set as a custom wrapper
         
     | 
| 
      
 112 
     | 
    
         
            +
                #
         
     | 
| 
      
 113 
     | 
    
         
            +
                # Example:
         
     | 
| 
      
 114 
     | 
    
         
            +
                #
         
     | 
| 
      
 115 
     | 
    
         
            +
                #   PutsDebuggerer.wrapper = true
         
     | 
| 
      
 116 
     | 
    
         
            +
                #   pd (x=1)
         
     | 
| 
      
 117 
     | 
    
         
            +
                #
         
     | 
| 
      
 118 
     | 
    
         
            +
                # Prints out:
         
     | 
| 
      
 119 
     | 
    
         
            +
                #
         
     | 
| 
      
 120 
     | 
    
         
            +
                #   [PD] /Users/User/example.rb:2
         
     | 
| 
      
 121 
     | 
    
         
            +
                #      > pd x=1
         
     | 
| 
      
 122 
     | 
    
         
            +
                #     => "1"
         
     | 
| 
      
 123 
     | 
    
         
            +
                #   ********************************************************************************
         
     | 
| 
      
 124 
     | 
    
         
            +
                attr_reader :wrapper
         
     | 
| 
      
 125 
     | 
    
         
            +
             
     | 
| 
      
 126 
     | 
    
         
            +
                def wrapper=(value)
         
     | 
| 
      
 127 
     | 
    
         
            +
                  if value.equal?(true)
         
     | 
| 
      
 128 
     | 
    
         
            +
                    @wrapper = WRAPPER_DEFAULT
         
     | 
| 
      
 129 
     | 
    
         
            +
                  elsif value == ''
         
     | 
| 
      
 130 
     | 
    
         
            +
                    @wrapper = nil
         
     | 
| 
      
 131 
     | 
    
         
            +
                  else
         
     | 
| 
      
 132 
     | 
    
         
            +
                    @wrapper = value
         
     | 
| 
      
 133 
     | 
    
         
            +
                  end
         
     | 
| 
      
 134 
     | 
    
         
            +
                end
         
     | 
| 
      
 135 
     | 
    
         
            +
             
     | 
| 
      
 136 
     | 
    
         
            +
                def wrapper?
         
     | 
| 
      
 137 
     | 
    
         
            +
                  !!@wrapper
         
     | 
| 
      
 138 
     | 
    
         
            +
                end
         
     | 
| 
      
 139 
     | 
    
         
            +
                
         
     | 
| 
       82 
140 
     | 
    
         
             
                # Footer to include at the bottom of every print out.
         
     | 
| 
       83 
141 
     | 
    
         
             
                # * Default value is `nil`
         
     | 
| 
       84 
142 
     | 
    
         
             
                # * Value `true` enables footer as `'*'*80`
         
     | 
| 
         @@ -174,7 +232,7 @@ module PutsDebuggerer 
     | 
|
| 
       174 
232 
     | 
    
         | 
| 
       175 
233 
     | 
    
         
             
                def print_engine=(engine)
         
     | 
| 
       176 
234 
     | 
    
         
             
                  if engine.nil?
         
     | 
| 
       177 
     | 
    
         
            -
                    @print_engine = PRINT_ENGINE_DEFAULT
         
     | 
| 
      
 235 
     | 
    
         
            +
                    @print_engine = Object.const_defined?(:AwesomePrint) ? PRINT_ENGINE_DEFAULT : :p
         
     | 
| 
       178 
236 
     | 
    
         
             
                  elsif engine.is_a?(Proc)
         
     | 
| 
       179 
237 
     | 
    
         
             
                    @print_engine = engine
         
     | 
| 
       180 
238 
     | 
    
         
             
                  else
         
     | 
| 
         @@ -206,12 +264,14 @@ module PutsDebuggerer 
     | 
|
| 
       206 
264 
     | 
    
         
             
                # * :announcer (string)
         
     | 
| 
       207 
265 
     | 
    
         
             
                # * :caller (array)
         
     | 
| 
       208 
266 
     | 
    
         
             
                # * :file (string)
         
     | 
| 
      
 267 
     | 
    
         
            +
                # * :wrapper (string)
         
     | 
| 
       209 
268 
     | 
    
         
             
                # * :footer (string)
         
     | 
| 
       210 
269 
     | 
    
         
             
                # * :header (string)
         
     | 
| 
       211 
270 
     | 
    
         
             
                # * :line_number (string)
         
     | 
| 
       212 
271 
     | 
    
         
             
                # * :pd_expression (string)
         
     | 
| 
       213 
272 
     | 
    
         
             
                # * :object (object)
         
     | 
| 
       214 
273 
     | 
    
         
             
                # * :object_printer (proc)
         
     | 
| 
      
 274 
     | 
    
         
            +
                # * :source_line_count (integer)
         
     | 
| 
       215 
275 
     | 
    
         
             
                #
         
     | 
| 
       216 
276 
     | 
    
         
             
                # NOTE: data for :object_printer is not a string, yet a proc that must
         
     | 
| 
       217 
277 
     | 
    
         
             
                # be called to output value. It is a proc as it automatically handles usage
         
     | 
| 
         @@ -289,9 +349,11 @@ module PutsDebuggerer 
     | 
|
| 
       289 
349 
     | 
    
         
             
                def options
         
     | 
| 
       290 
350 
     | 
    
         
             
                  {
         
     | 
| 
       291 
351 
     | 
    
         
             
                    header: header,
         
     | 
| 
      
 352 
     | 
    
         
            +
                    wrapper: wrapper,
         
     | 
| 
       292 
353 
     | 
    
         
             
                    footer: footer,
         
     | 
| 
       293 
354 
     | 
    
         
             
                    printer: printer,
         
     | 
| 
       294 
355 
     | 
    
         
             
                    print_engine: print_engine,
         
     | 
| 
      
 356 
     | 
    
         
            +
                    source_line_count: source_line_count,
         
     | 
| 
       295 
357 
     | 
    
         
             
                    app_path: app_path,
         
     | 
| 
       296 
358 
     | 
    
         
             
                    announcer: announcer,
         
     | 
| 
       297 
359 
     | 
    
         
             
                    formatter: formatter,
         
     | 
| 
         @@ -417,6 +479,7 @@ PutsDebuggerer.formatter = nil 
     | 
|
| 
       417 
479 
     | 
    
         
             
            PutsDebuggerer.app_path = nil
         
     | 
| 
       418 
480 
     | 
    
         
             
            PutsDebuggerer.caller = nil
         
     | 
| 
       419 
481 
     | 
    
         
             
            PutsDebuggerer.run_at = nil
         
     | 
| 
      
 482 
     | 
    
         
            +
            PutsDebuggerer.source_line_count = nil
         
     | 
| 
       420 
483 
     | 
    
         | 
| 
       421 
484 
     | 
    
         
             
            # Prints object with bonus info such as file name, line number and source
         
     | 
| 
       422 
485 
     | 
    
         
             
            # expression. Optionally prints out header and footer.
         
     | 
| 
         @@ -447,12 +510,15 @@ PutsDebuggerer.run_at = nil 
     | 
|
| 
       447 
510 
     | 
    
         
             
            #      > pd "Show me the source of the bug: #{bug}"
         
     | 
| 
       448 
511 
     | 
    
         
             
            #     => "Show me the source of the bug: beattle"
         
     | 
| 
       449 
512 
     | 
    
         
             
            #   [PD] /Users/User/finance_calculator_app/pd_test.rb:4 "What line number am I?"
         
     | 
| 
       450 
     | 
    
         
            -
            def pd( 
     | 
| 
      
 513 
     | 
    
         
            +
            def pd(*objects)
         
     | 
| 
      
 514 
     | 
    
         
            +
              options = objects.delete_at(-1) if objects.size > 1 && objects.last.is_a?(Hash)
         
     | 
| 
      
 515 
     | 
    
         
            +
              object = objects.compact.size > 1 ? objects : objects.first
         
     | 
| 
       451 
516 
     | 
    
         
             
              run_at = ((options && options[:run_at]) || PutsDebuggerer.run_at)
         
     | 
| 
       452 
517 
     | 
    
         | 
| 
       453 
518 
     | 
    
         
             
              if __run_pd__(object, run_at)
         
     | 
| 
       454 
519 
     | 
    
         
             
                __with_pd_options__(options) do |print_engine_options|
         
     | 
| 
       455 
     | 
    
         
            -
                   
     | 
| 
      
 520 
     | 
    
         
            +
                  run_number = PutsDebuggerer.run_at_global_number || PutsDebuggerer.run_at_number(object, run_at)
         
     | 
| 
      
 521 
     | 
    
         
            +
                  formatter_pd_data = __build_pd_data__(object, print_engine_options, PutsDebuggerer.source_line_count, run_number) #depth adds build method
         
     | 
| 
       456 
522 
     | 
    
         
             
                  stdout = $stdout
         
     | 
| 
       457 
523 
     | 
    
         
             
                  $stdout = sio = StringIO.new
         
     | 
| 
       458 
524 
     | 
    
         
             
                  PutsDebuggerer.formatter.call(formatter_pd_data)
         
     | 
| 
         @@ -510,7 +576,7 @@ end 
     | 
|
| 
       510 
576 
     | 
    
         
             
            #
         
     | 
| 
       511 
577 
     | 
    
         
             
            # prints out `3`
         
     | 
| 
       512 
578 
     | 
    
         
             
            def __caller_line_number__(caller_depth=0)
         
     | 
| 
       513 
     | 
    
         
            -
              caller[caller_depth][PutsDebuggerer::STACK_TRACE_CALL_LINE_NUMBER_REGEX, 1].to_i
         
     | 
| 
      
 579 
     | 
    
         
            +
              caller[caller_depth] && caller[caller_depth][PutsDebuggerer::STACK_TRACE_CALL_LINE_NUMBER_REGEX, 1].to_i
         
     | 
| 
       514 
580 
     | 
    
         
             
            end
         
     | 
| 
       515 
581 
     | 
    
         | 
| 
       516 
582 
     | 
    
         
             
            # Provides caller file starting 1 level above caller of
         
     | 
| 
         @@ -523,7 +589,7 @@ end 
     | 
|
| 
       523 
589 
     | 
    
         
             
            #
         
     | 
| 
       524 
590 
     | 
    
         
             
            # prints out `lib/example.rb`
         
     | 
| 
       525 
591 
     | 
    
         
             
            def __caller_file__(caller_depth=0)
         
     | 
| 
       526 
     | 
    
         
            -
              caller[caller_depth][PutsDebuggerer::STACK_TRACE_CALL_SOURCE_FILE_REGEX, 1]
         
     | 
| 
      
 592 
     | 
    
         
            +
              caller[caller_depth] && caller[caller_depth][PutsDebuggerer::STACK_TRACE_CALL_SOURCE_FILE_REGEX, 1]
         
     | 
| 
       527 
593 
     | 
    
         
             
            end
         
     | 
| 
       528 
594 
     | 
    
         | 
| 
       529 
595 
     | 
    
         | 
| 
         @@ -535,22 +601,28 @@ end 
     | 
|
| 
       535 
601 
     | 
    
         
             
            #   puts __caller_source_line__
         
     | 
| 
       536 
602 
     | 
    
         
             
            #
         
     | 
| 
       537 
603 
     | 
    
         
             
            # prints out `puts __caller_source_line__`
         
     | 
| 
       538 
     | 
    
         
            -
            def __caller_source_line__(caller_depth=0, source_file=nil, source_line_number=nil)
         
     | 
| 
      
 604 
     | 
    
         
            +
            def __caller_source_line__(caller_depth=0, source_line_count=nil, source_file=nil, source_line_number=nil)
         
     | 
| 
       539 
605 
     | 
    
         
             
              source_line_number ||= __caller_line_number__(caller_depth+1)
         
     | 
| 
       540 
606 
     | 
    
         
             
              source_file ||= __caller_file__(caller_depth+1)
         
     | 
| 
       541 
     | 
    
         
            -
              source_line =  
     | 
| 
      
 607 
     | 
    
         
            +
              source_line = ''
         
     | 
| 
       542 
608 
     | 
    
         
             
              if source_file == '(irb)'
         
     | 
| 
       543 
609 
     | 
    
         
             
                source_line = conf.io.line(source_line_number)
         
     | 
| 
       544 
610 
     | 
    
         
             
              else
         
     | 
| 
       545 
611 
     | 
    
         
             
                f = File.new(source_file)
         
     | 
| 
       546 
     | 
    
         
            -
                 
     | 
| 
       547 
     | 
    
         
            -
             
     | 
| 
       548 
     | 
    
         
            -
             
     | 
| 
       549 
     | 
    
         
            -
             
     | 
| 
       550 
     | 
    
         
            -
             
     | 
| 
       551 
     | 
    
         
            -
             
     | 
| 
       552 
     | 
    
         
            -
             
     | 
| 
      
 612 
     | 
    
         
            +
                if f.respond_to?(:readline) # Opal Ruby Compatibility
         
     | 
| 
      
 613 
     | 
    
         
            +
                  source_lines = []
         
     | 
| 
      
 614 
     | 
    
         
            +
                  begin
         
     | 
| 
      
 615 
     | 
    
         
            +
                    while f.lineno < source_line_number + source_line_count
         
     | 
| 
      
 616 
     | 
    
         
            +
                      file_line_number = f.lineno + 1
         
     | 
| 
      
 617 
     | 
    
         
            +
                      file_line = f.readline
         
     | 
| 
      
 618 
     | 
    
         
            +
                      if file_line_number >= source_line_number && file_line_number < source_line_number + source_line_count
         
     | 
| 
      
 619 
     | 
    
         
            +
                        source_lines << file_line
         
     | 
| 
      
 620 
     | 
    
         
            +
                      end
         
     | 
| 
      
 621 
     | 
    
         
            +
                    end
         
     | 
| 
      
 622 
     | 
    
         
            +
                  rescue EOFError
         
     | 
| 
      
 623 
     | 
    
         
            +
                    # Done
         
     | 
| 
       553 
624 
     | 
    
         
             
                  end
         
     | 
| 
      
 625 
     | 
    
         
            +
                  source_line = source_lines.join(' '*5)
         
     | 
| 
       554 
626 
     | 
    
         
             
                end
         
     | 
| 
       555 
627 
     | 
    
         
             
              end
         
     | 
| 
       556 
628 
     | 
    
         
             
              source_line
         
     | 
| 
         @@ -567,16 +639,19 @@ def __with_pd_options__(options=nil) 
     | 
|
| 
       567 
639 
     | 
    
         
             
              PutsDebuggerer.options = permanent_options
         
     | 
| 
       568 
640 
     | 
    
         
             
            end
         
     | 
| 
       569 
641 
     | 
    
         | 
| 
       570 
     | 
    
         
            -
            def __build_pd_data__(object, print_engine_options=nil)
         
     | 
| 
      
 642 
     | 
    
         
            +
            def __build_pd_data__(object, print_engine_options=nil, source_line_count=nil, run_number=nil)
         
     | 
| 
       571 
643 
     | 
    
         
             
              depth = PutsDebuggerer::CALLER_DEPTH_ZERO
         
     | 
| 
       572 
644 
     | 
    
         
             
              pd_data = {
         
     | 
| 
       573 
645 
     | 
    
         
             
                announcer: PutsDebuggerer.announcer,
         
     | 
| 
       574 
     | 
    
         
            -
                file: __caller_file__(depth) 
     | 
| 
      
 646 
     | 
    
         
            +
                file: __caller_file__(depth)&.sub(PutsDebuggerer.app_path.to_s, ''),
         
     | 
| 
       575 
647 
     | 
    
         
             
                line_number: __caller_line_number__(depth),
         
     | 
| 
       576 
     | 
    
         
            -
                pd_expression: __caller_pd_expression__(depth),
         
     | 
| 
      
 648 
     | 
    
         
            +
                pd_expression: __caller_pd_expression__(depth, source_line_count),
         
     | 
| 
      
 649 
     | 
    
         
            +
                run_number: run_number,
         
     | 
| 
       577 
650 
     | 
    
         
             
                object: object,
         
     | 
| 
       578 
651 
     | 
    
         
             
                object_printer: lambda do
         
     | 
| 
       579 
     | 
    
         
            -
                  if  
     | 
| 
      
 652 
     | 
    
         
            +
                  if object.is_a?(Exception) && object.respond_to?(:full_message)
         
     | 
| 
      
 653 
     | 
    
         
            +
                    puts object.full_message
         
     | 
| 
      
 654 
     | 
    
         
            +
                  elsif PutsDebuggerer.print_engine.is_a?(Proc)
         
     | 
| 
       580 
655 
     | 
    
         
             
                    PutsDebuggerer.print_engine.call(object)
         
     | 
| 
       581 
656 
     | 
    
         
             
                  else
         
     | 
| 
       582 
657 
     | 
    
         
             
                    if print_engine_options.to_h.empty?
         
     | 
| 
         @@ -593,6 +668,7 @@ def __build_pd_data__(object, print_engine_options=nil) 
     | 
|
| 
       593 
668 
     | 
    
         
             
                pd_data[:caller] = caller[start_depth..caller_depth].to_a
         
     | 
| 
       594 
669 
     | 
    
         
             
              end
         
     | 
| 
       595 
670 
     | 
    
         
             
              pd_data[:header] = PutsDebuggerer.header if PutsDebuggerer.header?
         
     | 
| 
      
 671 
     | 
    
         
            +
              pd_data[:wrapper] = PutsDebuggerer.wrapper if PutsDebuggerer.wrapper?
         
     | 
| 
       596 
672 
     | 
    
         
             
              pd_data[:footer] = PutsDebuggerer.footer if PutsDebuggerer.footer?
         
     | 
| 
       597 
673 
     | 
    
         
             
              pd_data
         
     | 
| 
       598 
674 
     | 
    
         
             
            end
         
     | 
| 
         @@ -601,9 +677,9 @@ def __format_pd_expression__(expression, object) 
     | 
|
| 
       601 
677 
     | 
    
         
             
              "\n   > #{expression}\n  =>"
         
     | 
| 
       602 
678 
     | 
    
         
             
            end
         
     | 
| 
       603 
679 
     | 
    
         | 
| 
       604 
     | 
    
         
            -
            def __caller_pd_expression__(depth=0)
         
     | 
| 
      
 680 
     | 
    
         
            +
            def __caller_pd_expression__(depth=0, source_line_count=nil)
         
     | 
| 
       605 
681 
     | 
    
         
             
              # Caller Source Line Depth 2 = 1 to pd method + 1 to caller
         
     | 
| 
       606 
     | 
    
         
            -
              source_line = __caller_source_line__(depth+1)
         
     | 
| 
      
 682 
     | 
    
         
            +
              source_line = __caller_source_line__(depth+1, source_line_count)
         
     | 
| 
       607 
683 
     | 
    
         
             
              source_line = __extract_pd_expression__(source_line)
         
     | 
| 
       608 
684 
     | 
    
         
             
              source_line = source_line.gsub(/(^'|'$)/, '"') if source_line.start_with?("'") && source_line.end_with?("'")
         
     | 
| 
       609 
685 
     | 
    
         
             
              source_line = source_line.gsub(/(^\(|\)$)/, '') if source_line.start_with?("(") && source_line.end_with?(")")
         
     | 
| 
         @@ -618,5 +694,5 @@ end 
     | 
|
| 
       618 
694 
     | 
    
         
             
            #
         
     | 
| 
       619 
695 
     | 
    
         
             
            # outputs `(x=1)`
         
     | 
| 
       620 
696 
     | 
    
         
             
            def __extract_pd_expression__(source_line)
         
     | 
| 
       621 
     | 
    
         
            -
              source_line.strip
         
     | 
| 
      
 697 
     | 
    
         
            +
              source_line.to_s.strip
         
     | 
| 
       622 
698 
     | 
    
         
             
            end
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,14 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: puts_debuggerer
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.9.0
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Andy Maleh
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire:
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date: 2020- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2020-07-24 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: awesome_print
         
     | 
| 
         @@ -158,9 +158,11 @@ email: andy.am@gmail.com 
     | 
|
| 
       158 
158 
     | 
    
         
             
            executables: []
         
     | 
| 
       159 
159 
     | 
    
         
             
            extensions: []
         
     | 
| 
       160 
160 
     | 
    
         
             
            extra_rdoc_files:
         
     | 
| 
      
 161 
     | 
    
         
            +
            - CHANGELOG.md
         
     | 
| 
       161 
162 
     | 
    
         
             
            - LICENSE.txt
         
     | 
| 
       162 
163 
     | 
    
         
             
            - README.md
         
     | 
| 
       163 
164 
     | 
    
         
             
            files:
         
     | 
| 
      
 165 
     | 
    
         
            +
            - CHANGELOG.md
         
     | 
| 
       164 
166 
     | 
    
         
             
            - LICENSE.txt
         
     | 
| 
       165 
167 
     | 
    
         
             
            - README.md
         
     | 
| 
       166 
168 
     | 
    
         
             
            - VERSION
         
     |