puts_debuggerer 0.10.1 → 0.10.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2fd0277b6264431cf1d1e83db01166e95107cbbc6dc45b0eff9adac444650372
4
- data.tar.gz: 31276c4cb27085ccd264897fa7305e7fe1740d8f6a4a0901c73e1e2ec179c458
3
+ metadata.gz: c10b7cd1e10ee4448130b42cf869c55904445ec9038875c4da4339813ba7b6d6
4
+ data.tar.gz: 973aaad4a4eda5bb9ef7add02f0b3a3b991bb84f6fd2ab461281c03aa5cc1404
5
5
  SHA512:
6
- metadata.gz: 96cb360a70d4118c0fc63a17b0d5d1b883f40177a8765efe2a9e135afe872686ee4090ba5e8bb5c456077545225b6a92737d2de1c315e0b3ce6184ee53ef9ac1
7
- data.tar.gz: 751582b302545b1f4bea4fb7704125e0eb3e95057c4d0a3435042b3b2cddf2d13026f60318ef0da777c72f6b004479e8f64d0fc78f374b19ad9a8db9a78ed494
6
+ metadata.gz: 9b029b0cfeb9b219313e80b72c8be7094db40101a51bc6b430254110c4e2b662eaed5706831372909f950fa1f7503a20544553491d29f275f004ab26be2c1419
7
+ data.tar.gz: cdd0aaa7734d5b98a1efba63fdc8aebd514ad76a694a1362b066728ffb0605005f8093d83355aa7c10d32a26eedf2e372042a62ecfdc0e04271fa2e24899ddb1
@@ -1,5 +1,9 @@
1
1
  # Change Log
2
2
 
3
+ ## 0.10.2
4
+
5
+ - Improve Opal Ruby compatibility by displaying source file/line
6
+
3
7
  ## 0.10.1
4
8
 
5
9
  - Remove the need for specifying `require 'ap'` before `require 'pd'`
data/README.md CHANGED
@@ -302,7 +302,7 @@ There are many more options and powerful features in [puts_debuggerer](https://r
302
302
  Add the following to bundler's `Gemfile`.
303
303
 
304
304
  ```ruby
305
- gem 'puts_debuggerer', '~> 0.10.1'
305
+ gem 'puts_debuggerer', '~> 0.10.2'
306
306
  ```
307
307
 
308
308
  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.
@@ -312,7 +312,7 @@ This is the recommended way for [Rails](rubyonrails.org) apps. Optionally, you m
312
312
  Or manually install and require library.
313
313
 
314
314
  ```bash
315
- gem install puts_debuggerer -v0.10.1
315
+ gem install puts_debuggerer -v0.10.2
316
316
  ```
317
317
 
318
318
  ```ruby
@@ -981,10 +981,21 @@ Prints out `puts __caller_source_line__`
981
981
  - IRB
982
982
  - Rails Console.
983
983
 
984
- It provides partial-compatibility for [Opal Ruby](https://opalrb.com/) by excluding AwesomePrint (opting for `:p` printer instead), with everything working except these features:
985
- - File name display
986
- - Line number display
987
- - Source code call display
984
+ ### Opal Ruby
985
+
986
+ [puts_debuggerer](https://rubygems.org/gems/puts_debuggerer) provides partial-compatibility in [Opal Ruby](https://opalrb.com/) with everything working except:
987
+ - AwesomePrint (using the `:p` printer instead)
988
+ - Source code display
989
+
990
+ [puts_debuggerer](https://rubygems.org/gems/puts_debuggerer) renders clickable source file/line links in Opal Ruby that take you to the source code in the web browser.
991
+
992
+ Here is an example of `pd` output in Opal:
993
+
994
+ ```
995
+ [PD] http://localhost:3000/assets/views/garderie_rainbow_daily_agenda/app_view.self-72626d75e0f68a619b1c8ad139535d799d45ab6c730d083820b790d71338e983.js?body=1:72:12
996
+ >
997
+ => "body"
998
+ ```
988
999
 
989
1000
  ## Change Log
990
1001
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.10.1
1
+ 0.10.2
@@ -1,19 +1,9 @@
1
- require 'stringio'
2
-
3
1
  require 'puts_debuggerer/core_ext/kernel'
2
+ require 'puts_debuggerer/core_ext/logger'
3
+ require 'puts_debuggerer/core_ext/logging/logger'
4
4
  require 'puts_debuggerer/run_determiner'
5
5
  require 'puts_debuggerer/source_file'
6
6
 
7
- # in case 'logger' is not required
8
- class Logger
9
- end
10
-
11
- # in case 'logging' is not required
12
- module Logging
13
- class Logger
14
- end
15
- end
16
-
17
7
  module PutsDebuggerer
18
8
  SOURCE_LINE_COUNT_DEFAULT = 1
19
9
  HEADER_DEFAULT = '*'*80
@@ -58,15 +48,17 @@ module PutsDebuggerer
58
48
  FORMATTER_DEFAULT = -> (data) {
59
49
  puts data[:wrapper] if data[:wrapper]
60
50
  puts data[:header] if data[:header]
61
- print "#{data[:announcer]} #{data[:file]}:#{data[:line_number]}#{" (run:#{data[:run_number]})" if data[:run_number]}#{__format_pd_expression__(data[:pd_expression], data[:object])} "
51
+ print "#{data[:announcer]} #{data[:file]}#{':' if data[:line_number]}#{data[:line_number]}#{" (run:#{data[:run_number]})" if data[:run_number]}#{__format_pd_expression__(data[:pd_expression], data[:object])} "
62
52
  data[:object_printer].call
63
53
  puts data[:caller].map {|l| ' ' + l} unless data[:caller].to_a.empty?
64
54
  puts data[:footer] if data[:footer]
65
55
  puts data[:wrapper] if data[:wrapper]
66
56
  }
67
57
  CALLER_DEPTH_ZERO = 4 #depth includes pd + with_options method + nested block + build_pd_data method
58
+ CALLER_DEPTH_ZERO_OPAL = -1 #depth includes pd + with_options method + nested block + build_pd_data method
68
59
  STACK_TRACE_CALL_LINE_NUMBER_REGEX = /\:(\d+)\:in /
69
60
  STACK_TRACE_CALL_SOURCE_FILE_REGEX = /[ ]*([^:]+)\:\d+\:in /
61
+ STACK_TRACE_CALL_SOURCE_FILE_REGEX_OPAL = /(http[^\)]+)/
70
62
 
71
63
  class << self
72
64
  # Application root path to exclude when printing out file path
@@ -278,7 +270,7 @@ module PutsDebuggerer
278
270
  end
279
271
  end
280
272
 
281
- def print_engine_default
273
+ def print_engine_default
282
274
  Object.const_defined?(:AwesomePrint) ? PRINT_ENGINE_DEFAULT : :p
283
275
  end
284
276
 
@@ -503,196 +495,3 @@ PutsDebuggerer.app_path = nil
503
495
  PutsDebuggerer.caller = nil
504
496
  PutsDebuggerer.run_at = nil
505
497
  PutsDebuggerer.source_line_count = nil
506
-
507
- # Prints object with bonus info such as file name, line number and source
508
- # expression. Optionally prints out header and footer.
509
- # Lookup PutsDebuggerer attributes for more details about configuration options.
510
- #
511
- # Simply invoke global `pd` method anywhere you'd like to see line number and source code with output.
512
- # If the argument is a pure string, the print out is simplified by not showing duplicate source.
513
- #
514
- # Quickly locate printed lines using Find feature (e.g. CTRL+F) by looking for:
515
- # * \[PD\]
516
- # * file:line_number
517
- # * ruby expression.
518
- #
519
- # This gives you the added benefit of easily removing your pd statements later on from the code.
520
- #
521
- # Happy puts_debuggerering!
522
- #
523
- # Example Code:
524
- #
525
- # # /Users/User/finance_calculator_app/pd_test.rb # line 1
526
- # bug = 'beattle' # line 2
527
- # pd "Show me the source of the bug: #{bug}" # line 3
528
- # pd 'What line number am I?' # line 4
529
- #
530
- # Example Printout:
531
- #
532
- # [PD] /Users/User/finance_calculator_app/pd_test.rb:3
533
- # > pd "Show me the source of the bug: #{bug}"
534
- # => "Show me the source of the bug: beattle"
535
- # [PD] /Users/User/finance_calculator_app/pd_test.rb:4 "What line number am I?"
536
- def pd(*objects)
537
- options = PutsDebuggerer.determine_options(objects) || {}
538
- object = PutsDebuggerer.determine_object(objects)
539
- run_at = PutsDebuggerer.determine_run_at(options)
540
- printer = PutsDebuggerer.determine_printer(options)
541
- pd_inspect = options.delete(:pd_inspect)
542
- logger_formatter_decorated = PutsDebuggerer.printer.is_a?(Logger) && PutsDebuggerer.printer.formatter != PutsDebuggerer.logger_original_formatter
543
- logging_layouts_decorated = PutsDebuggerer.printer.is_a?(Logging::Logger) && PutsDebuggerer.printer.appenders.map(&:layout) != (PutsDebuggerer.logging_original_layouts.values)
544
-
545
- string = nil
546
- if PutsDebuggerer::RunDeterminer.run_pd?(object, run_at)
547
- __with_pd_options__(options) do |print_engine_options|
548
- run_number = PutsDebuggerer::RunDeterminer.run_number(object, run_at)
549
- formatter_pd_data = __build_pd_data__(object, print_engine_options, PutsDebuggerer.source_line_count, run_number, pd_inspect, logger_formatter_decorated, logging_layouts_decorated) #depth adds build method
550
- stdout = $stdout
551
- $stdout = sio = StringIO.new
552
- PutsDebuggerer.formatter.call(formatter_pd_data)
553
- $stdout = stdout
554
- string = sio.string
555
- if PutsDebuggerer.printer.is_a?(Proc)
556
- PutsDebuggerer.printer.call(string)
557
- elsif PutsDebuggerer.printer.is_a?(Logger)
558
- logger_formatter = PutsDebuggerer.printer.formatter
559
- begin
560
- PutsDebuggerer.printer.formatter = PutsDebuggerer.logger_original_formatter
561
- PutsDebuggerer.printer.debug(string)
562
- ensure
563
- PutsDebuggerer.printer.formatter = logger_formatter
564
- end
565
- elsif PutsDebuggerer.printer.is_a?(Logging::Logger)
566
- logging_layouts = PutsDebuggerer.printer.appenders.reduce({}) do |hash, appender|
567
- hash.merge(appender => appender.layout)
568
- end
569
- begin
570
- PutsDebuggerer.logging_original_layouts.each do |appender, original_layout|
571
- appender.layout = original_layout
572
- end
573
- PutsDebuggerer.printer.debug(string)
574
- ensure
575
- PutsDebuggerer.logging_original_layouts.each do |appender, original_layout|
576
- appender.layout = logging_layouts[appender]
577
- end
578
- end
579
- elsif PutsDebuggerer.printer != false
580
- send(PutsDebuggerer.send(:printer), string)
581
- end
582
- end
583
- end
584
-
585
- printer ? object : string
586
- end
587
-
588
- # Provides caller line number starting 1 level above caller of
589
- # this method.
590
- #
591
- # Example:
592
- #
593
- # # lib/example.rb # line 1
594
- # puts "Print out __caller_line_number__" # line 2
595
- # puts __caller_line_number__ # line 3
596
- #
597
- # prints out `3`
598
- def __caller_line_number__(caller_depth=0)
599
- caller[caller_depth] && caller[caller_depth][PutsDebuggerer::STACK_TRACE_CALL_LINE_NUMBER_REGEX, 1].to_i
600
- end
601
-
602
- # Provides caller file starting 1 level above caller of
603
- # this method.
604
- #
605
- # Example:
606
- #
607
- # # File Name: lib/example.rb
608
- # puts __caller_file__
609
- #
610
- # prints out `lib/example.rb`
611
- def __caller_file__(caller_depth=0)
612
- result = caller[caller_depth] && caller[caller_depth][PutsDebuggerer::STACK_TRACE_CALL_SOURCE_FILE_REGEX, 1]
613
- end
614
-
615
-
616
- # Provides caller source line starting 1 level above caller of
617
- # this method.
618
- #
619
- # Example:
620
- #
621
- # puts __caller_source_line__
622
- #
623
- # prints out `puts __caller_source_line__`
624
- def __caller_source_line__(caller_depth=0, source_line_count=nil, source_file=nil, source_line_number=nil)
625
- source_line_number ||= __caller_line_number__(caller_depth+1)
626
- source_file ||= __caller_file__(caller_depth+1)
627
- source_line = ''
628
- if source_file == '(irb)'
629
- source_line = conf.io.line(source_line_number) # TODO handle multi-lines in source_line_count
630
- else
631
- source_line = PutsDebuggerer::SourceFile.new(source_file).source(source_line_count, source_line_number)
632
- end
633
- source_line
634
- end
635
-
636
- private
637
-
638
- def __with_pd_options__(options=nil)
639
- options ||= {}
640
- permanent_options = PutsDebuggerer.options
641
- PutsDebuggerer.options = options.select {|option, _| PutsDebuggerer.options.keys.include?(option)}
642
- print_engine_options = options.delete_if {|option, _| PutsDebuggerer.options.keys.include?(option)}
643
- yield print_engine_options
644
- PutsDebuggerer.options = permanent_options
645
- end
646
-
647
- def __build_pd_data__(object, print_engine_options=nil, source_line_count=nil, run_number=nil, pd_inspect=false, logger_formatter_decorated=false, logging_layouts_decorated=false)
648
- depth = PutsDebuggerer::CALLER_DEPTH_ZERO
649
- depth += 1 if pd_inspect
650
- depth += 4 if pd_inspect && logger_formatter_decorated
651
- depth += 8 if pd_inspect && logging_layouts_decorated
652
- pd_data = {
653
- announcer: PutsDebuggerer.announcer,
654
- file: __caller_file__(depth)&.sub(PutsDebuggerer.app_path.to_s, ''),
655
- line_number: __caller_line_number__(depth),
656
- pd_expression: __caller_pd_expression__(depth, source_line_count),
657
- run_number: run_number,
658
- object: object,
659
- object_printer: PutsDebuggerer::OBJECT_PRINTER_DEFAULT.call(object, print_engine_options, source_line_count, run_number)
660
- }
661
- pd_data[:caller] = __caller_caller__(depth)
662
- ['header', 'wrapper', 'footer'].each do |boundary_option|
663
- pd_data[boundary_option.to_sym] = PutsDebuggerer.send(boundary_option) if PutsDebuggerer.send("#{boundary_option}?")
664
- end
665
- pd_data
666
- end
667
-
668
- # Returns the caller stack trace of the caller of pd
669
- def __caller_caller__(depth)
670
- return unless PutsDebuggerer.caller?
671
- start_depth = depth.to_i + 1
672
- caller_depth = PutsDebuggerer.caller == -1 ? -1 : (start_depth + PutsDebuggerer.caller)
673
- caller[start_depth..caller_depth].to_a
674
- end
675
-
676
- def __format_pd_expression__(expression, object)
677
- "\n > #{expression}\n =>"
678
- end
679
-
680
- def __caller_pd_expression__(depth=0, source_line_count=nil)
681
- # Caller Source Line Depth 2 = 1 to pd method + 1 to caller
682
- source_line = __caller_source_line__(depth+1, source_line_count)
683
- source_line = __extract_pd_expression__(source_line)
684
- source_line = source_line.gsub(/(^'|'$)/, '"') if source_line.start_with?("'") && source_line.end_with?("'")
685
- source_line = source_line.gsub(/(^\(|\)$)/, '') if source_line.start_with?("(") && source_line.end_with?(")")
686
- source_line
687
- end
688
-
689
- # Extracts pd source line expression.
690
- #
691
- # Example:
692
- #
693
- # __extract_pd_expression__("pd (x=1)")
694
- #
695
- # outputs `(x=1)`
696
- def __extract_pd_expression__(source_line)
697
- source_line.to_s.strip
698
- end
@@ -1,6 +1,217 @@
1
+ require 'stringio'
2
+
1
3
  module Kernel
4
+ # Prints object with bonus info such as file name, line number and source
5
+ # expression. Optionally prints out header and footer.
6
+ # Lookup PutsDebuggerer attributes for more details about configuration options.
7
+ #
8
+ # Simply invoke global `pd` method anywhere you'd like to see line number and source code with output.
9
+ # If the argument is a pure string, the print out is simplified by not showing duplicate source.
10
+ #
11
+ # Quickly locate printed lines using Find feature (e.g. CTRL+F) by looking for:
12
+ # * \[PD\]
13
+ # * file:line_number
14
+ # * ruby expression.
15
+ #
16
+ # This gives you the added benefit of easily removing your pd statements later on from the code.
17
+ #
18
+ # Happy puts_debuggerering!
19
+ #
20
+ # Example Code:
21
+ #
22
+ # # /Users/User/finance_calculator_app/pd_test.rb # line 1
23
+ # bug = 'beattle' # line 2
24
+ # pd "Show me the source of the bug: #{bug}" # line 3
25
+ # pd 'What line number am I?' # line 4
26
+ #
27
+ # Example Printout:
28
+ #
29
+ # [PD] /Users/User/finance_calculator_app/pd_test.rb:3
30
+ # > pd "Show me the source of the bug: #{bug}"
31
+ # => "Show me the source of the bug: beattle"
32
+ # [PD] /Users/User/finance_calculator_app/pd_test.rb:4 "What line number am I?"
33
+ def pd(*objects)
34
+ options = PutsDebuggerer.determine_options(objects) || {}
35
+ object = PutsDebuggerer.determine_object(objects)
36
+ run_at = PutsDebuggerer.determine_run_at(options)
37
+ printer = PutsDebuggerer.determine_printer(options)
38
+ pd_inspect = options.delete(:pd_inspect)
39
+ logger_formatter_decorated = PutsDebuggerer.printer.is_a?(Logger) && PutsDebuggerer.printer.formatter != PutsDebuggerer.logger_original_formatter
40
+ logging_layouts_decorated = PutsDebuggerer.printer.is_a?(Logging::Logger) && PutsDebuggerer.printer.appenders.map(&:layout) != (PutsDebuggerer.logging_original_layouts.values)
41
+
42
+ string = nil
43
+ if PutsDebuggerer::RunDeterminer.run_pd?(object, run_at)
44
+ __with_pd_options__(options) do |print_engine_options|
45
+ run_number = PutsDebuggerer::RunDeterminer.run_number(object, run_at)
46
+ formatter_pd_data = __build_pd_data__(object, print_engine_options: print_engine_options, source_line_count: PutsDebuggerer.source_line_count, run_number: run_number, pd_inspect: pd_inspect, logger_formatter_decorated: logger_formatter_decorated, logging_layouts_decorated: logging_layouts_decorated)
47
+ stdout = $stdout
48
+ $stdout = sio = StringIO.new
49
+ PutsDebuggerer.formatter.call(formatter_pd_data)
50
+ $stdout = stdout
51
+ string = sio.string
52
+ if PutsDebuggerer.printer.is_a?(Proc)
53
+ PutsDebuggerer.printer.call(string)
54
+ elsif PutsDebuggerer.printer.is_a?(Logger)
55
+ logger_formatter = PutsDebuggerer.printer.formatter
56
+ begin
57
+ PutsDebuggerer.printer.formatter = PutsDebuggerer.logger_original_formatter
58
+ PutsDebuggerer.printer.debug(string)
59
+ ensure
60
+ PutsDebuggerer.printer.formatter = logger_formatter
61
+ end
62
+ elsif PutsDebuggerer.printer.is_a?(Logging::Logger)
63
+ logging_layouts = PutsDebuggerer.printer.appenders.reduce({}) do |hash, appender|
64
+ hash.merge(appender => appender.layout)
65
+ end
66
+ begin
67
+ PutsDebuggerer.logging_original_layouts.each do |appender, original_layout|
68
+ appender.layout = original_layout
69
+ end
70
+ PutsDebuggerer.printer.debug(string)
71
+ ensure
72
+ PutsDebuggerer.logging_original_layouts.each do |appender, original_layout|
73
+ appender.layout = logging_layouts[appender]
74
+ end
75
+ end
76
+ elsif PutsDebuggerer.printer != false
77
+ send(PutsDebuggerer.send(:printer), string)
78
+ end
79
+ end
80
+ end
81
+
82
+ printer ? object : string
83
+ end
84
+
85
+ # Implement caller backtrace method in Opal since it returns an empty array in Opal v1
86
+ if RUBY_PLATFORM == 'opal'
87
+ def caller
88
+ begin
89
+ raise 'error'
90
+ rescue => e
91
+ e.backtrace[2..-1]
92
+ end
93
+ end
94
+ end
95
+
2
96
  def pd_inspect
3
97
  pd self, printer: false, pd_inspect: true
4
98
  end
5
99
  alias pdi pd_inspect
100
+
101
+ # Provides caller line number starting 1 level above caller of
102
+ # this method.
103
+ #
104
+ # Example:
105
+ #
106
+ # # lib/example.rb # line 1
107
+ # puts "Print out __caller_line_number__" # line 2
108
+ # puts __caller_line_number__ # line 3
109
+ #
110
+ # prints out `3`
111
+ def __caller_line_number__(caller_depth=0)
112
+ return if RUBY_PLATFORM == 'opal'
113
+ caller[caller_depth] && caller[caller_depth][PutsDebuggerer::STACK_TRACE_CALL_LINE_NUMBER_REGEX, 1].to_i
114
+ end
115
+
116
+ # Provides caller file starting 1 level above caller of
117
+ # this method.
118
+ #
119
+ # Example:
120
+ #
121
+ # # File Name: lib/example.rb
122
+ # puts __caller_file__
123
+ #
124
+ # prints out `lib/example.rb`
125
+ def __caller_file__(caller_depth=0)
126
+ regex = RUBY_PLATFORM == 'opal' ? PutsDebuggerer::STACK_TRACE_CALL_SOURCE_FILE_REGEX_OPAL : PutsDebuggerer::STACK_TRACE_CALL_SOURCE_FILE_REGEX
127
+ caller[caller_depth] && caller[caller_depth][regex, 1]
128
+ end
129
+
130
+
131
+ # Provides caller source line starting 1 level above caller of
132
+ # this method.
133
+ #
134
+ # Example:
135
+ #
136
+ # puts __caller_source_line__
137
+ #
138
+ # prints out `puts __caller_source_line__`
139
+ def __caller_source_line__(caller_depth=0, source_line_count=nil, source_file=nil, source_line_number=nil)
140
+ source_line_number ||= __caller_line_number__(caller_depth+1)
141
+ source_file ||= __caller_file__(caller_depth+1)
142
+ source_line = ''
143
+ if source_file == '(irb)'
144
+ source_line = conf.io.line(source_line_number) # TODO handle multi-lines in source_line_count
145
+ else
146
+ source_line = PutsDebuggerer::SourceFile.new(source_file).source(source_line_count, source_line_number)
147
+ end
148
+ source_line
149
+ end
150
+
151
+ private
152
+
153
+ def __with_pd_options__(options=nil)
154
+ options ||= {}
155
+ permanent_options = PutsDebuggerer.options
156
+ PutsDebuggerer.options = options.select {|option, _| PutsDebuggerer.options.keys.include?(option)}
157
+ print_engine_options = options.delete_if {|option, _| PutsDebuggerer.options.keys.include?(option)}
158
+ yield print_engine_options
159
+ PutsDebuggerer.options = permanent_options
160
+ end
161
+
162
+ def __build_pd_data__(object, print_engine_options:nil, source_line_count:nil, run_number:nil, pd_inspect:false, logger_formatter_decorated:false, logging_layouts_decorated:false)
163
+ depth = RUBY_PLATFORM == 'opal' ? PutsDebuggerer::CALLER_DEPTH_ZERO_OPAL : PutsDebuggerer::CALLER_DEPTH_ZERO
164
+ if pd_inspect
165
+ depth += 1
166
+ depth += 4 if logger_formatter_decorated
167
+ depth += 8 if logging_layouts_decorated
168
+ end
169
+
170
+ pd_data = {
171
+ announcer: PutsDebuggerer.announcer,
172
+ file: __caller_file__(depth)&.sub(PutsDebuggerer.app_path.to_s, ''),
173
+ line_number: __caller_line_number__(depth),
174
+ pd_expression: __caller_pd_expression__(depth, source_line_count),
175
+ run_number: run_number,
176
+ object: object,
177
+ object_printer: PutsDebuggerer::OBJECT_PRINTER_DEFAULT.call(object, print_engine_options, source_line_count, run_number)
178
+ }
179
+ pd_data[:caller] = __caller_caller__(depth)
180
+ ['header', 'wrapper', 'footer'].each do |boundary_option|
181
+ pd_data[boundary_option.to_sym] = PutsDebuggerer.send(boundary_option) if PutsDebuggerer.send("#{boundary_option}?")
182
+ end
183
+ pd_data
184
+ end
185
+
186
+ # Returns the caller stack trace of the caller of pd
187
+ def __caller_caller__(depth)
188
+ return unless PutsDebuggerer.caller?
189
+ start_depth = depth.to_i + 1
190
+ caller_depth = PutsDebuggerer.caller == -1 ? -1 : (start_depth + PutsDebuggerer.caller)
191
+ caller[start_depth..caller_depth].to_a
192
+ end
193
+
194
+ def __format_pd_expression__(expression, object)
195
+ "\n > #{expression}\n =>"
196
+ end
197
+
198
+ def __caller_pd_expression__(depth=0, source_line_count=nil)
199
+ # Caller Source Line Depth 2 = 1 to pd method + 1 to caller
200
+ source_line = __caller_source_line__(depth+1, source_line_count)
201
+ source_line = __extract_pd_expression__(source_line)
202
+ source_line = source_line.gsub(/(^'|'$)/, '"') if source_line.start_with?("'") && source_line.end_with?("'")
203
+ source_line = source_line.gsub(/(^\(|\)$)/, '') if source_line.start_with?("(") && source_line.end_with?(")")
204
+ source_line
205
+ end
206
+
207
+ # Extracts pd source line expression.
208
+ #
209
+ # Example:
210
+ #
211
+ # __extract_pd_expression__("pd (x=1)")
212
+ #
213
+ # outputs `(x=1)`
214
+ def __extract_pd_expression__(source_line)
215
+ source_line.to_s.strip
216
+ end
6
217
  end
@@ -0,0 +1,3 @@
1
+ # in case 'logger' is not required
2
+ class Logger
3
+ end
@@ -0,0 +1,5 @@
1
+ # in case 'logging' is not required
2
+ module Logging
3
+ class Logger
4
+ end
5
+ end
@@ -1,11 +1,12 @@
1
1
  module PutsDebuggerer
2
2
  class SourceFile
3
3
  def initialize(file_path)
4
- @file = File.new(file_path)
4
+ @file = File.new(file_path) if file_path
5
5
  end
6
6
 
7
7
  def source(source_line_count, source_line_number)
8
- @source = ''
8
+ @source = ''
9
+ return @source if RUBY_PLATFORM == 'opal'
9
10
  # For Opal Ruby compatibility, skip source lines if file does not respond to readline (as in Opal)
10
11
  lines = source_lines(source_line_count, source_line_number)
11
12
  @source = lines.join(' '*5) if @file.respond_to?(:readline)
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.10.1
4
+ version: 0.10.2
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-09-04 00:00:00.000000000 Z
11
+ date: 2020-10-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: awesome_print
@@ -164,6 +164,20 @@ dependencies:
164
164
  - - ">="
165
165
  - !ruby/object:Gem::Version
166
166
  version: 2.3.0
167
+ - !ruby/object:Gem::Dependency
168
+ name: rake-tui
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
167
181
  description: |
168
182
  Debuggers are great! They help us troubleshoot complicated programming problems by inspecting values produced by code, line by line. They are invaluable when trying to understand what is going on in a large application composed of thousands or millions of lines of code.
169
183
  In day-to-day test-driven development and simple debugging though, a puts statement can be a lot quicker in revealing what is going on than halting execution completely just to inspect a single value or a few. This is certainly true when writing the simplest possible code that could possibly work, and running a test every few seconds or minutes. Problem is you need to locate puts statements in large output logs, know which methods were invoked, find out what variable names are being printed, and see nicely formatted output. Enter puts_debuggerer. A guilt-free puts debugging Ruby gem FTW that prints file names, line numbers, code statements, and formats output nicely courtesy of awesome_print.
@@ -183,6 +197,8 @@ files:
183
197
  - lib/pd.rb
184
198
  - lib/puts_debuggerer.rb
185
199
  - lib/puts_debuggerer/core_ext/kernel.rb
200
+ - lib/puts_debuggerer/core_ext/logger.rb
201
+ - lib/puts_debuggerer/core_ext/logging/logger.rb
186
202
  - lib/puts_debuggerer/run_determiner.rb
187
203
  - lib/puts_debuggerer/source_file.rb
188
204
  homepage: http://github.com/AndyObtiva/puts_debuggerer