Skip to content

Commit 80d4be6

Browse files
committed
Update docs
1 parent 7511add commit 80d4be6

File tree

4 files changed

+23
-12
lines changed

4 files changed

+23
-12
lines changed

README.md

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ If you like [Awesome_Print](https://rubygems.org/gems/awesome_print) (or [Amazin
1111

1212
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.
1313

14-
In day-to-day test-driven development and simple app 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. Still, there are a number of problems with puts debugging, like difficulty in locating puts statements in a large output log, knowing which methods and line numbers were invoked, identifying which variables were printed, and seeing the content of structured hashes and arrays in an understandable format.
14+
In day-to-day test-driven development and simple app 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. Still, there are a number of problems with puts debugging, like difficulty in locating puts statements in a large output log, knowing which files, line numbers, and methods the puts statements were invoked from, identifying which variables were printed, and seeing the content of structured hashes and arrays in an understandable format.
1515

16-
Enter [puts_debuggerer](https://rubygems.org/gems/puts_debuggerer)! A guilt-free puts debugging Ruby gem FTW that prints file names, line numbers, invoked class methods, code statements, headers, footers, stack traces, and formats output nicely courtesy of [awesome_print](https://rubygems.org/gems/awesome_print) (or [amazing_print](https://github.com/amazing-print/amazing_print) if you prefer).
16+
Enter [puts_debuggerer](https://rubygems.org/gems/puts_debuggerer)! A guilt-free puts debugging Ruby gem FTW that prints file names, line numbers, class names, method names, code statements, headers, footers, and stack traces; and formats output nicely courtesy of [awesome_print](https://rubygems.org/gems/awesome_print) (or [amazing_print](https://github.com/amazing-print/amazing_print) if you prefer).
1717

1818
[puts_debuggerer](https://rubygems.org/gems/puts_debuggerer) automates tips mentioned in [this blog post](https://tenderlovemaking.com/2016/02/05/i-am-a-puts-debuggerer.html) by Aaron Patterson using the `pd` method available everywhere after requiring the [gem](https://rubygems.org/gems/puts_debuggerer).
1919

@@ -39,7 +39,7 @@ Output:
3939
=> "Beatles"
4040
```
4141

42-
`pd` revealed that the variable contains the band name "Beatles" as its value not the bug "Beetle", in addition to revealing the printed code statement `pd bug_or_band`, the file name `/Users/User/trivia_app.rb`, the line number `6`, the class name `TriviaApp`, and the invoked method name `question`.
42+
`pd` revealed that the variable contains the band name "Beatles" not the bug "Beetle", in addition to revealing the printed code statement `pd bug_or_band`, the file name `/Users/User/trivia_app.rb`, the line number `6`, the class name `TriviaApp`, and the method name `question`.
4343

4444
## Background
4545

@@ -72,7 +72,7 @@ Which gets lost in a logging stream such as:
7272
(0.2ms) COMMIT
7373
```
7474

75-
Here is a simple example using `pd` instead, which provides everything the puts statements above provide in addition to deducing the file name, line number, and invoked class method automatically for dead-easy debugging:
75+
Here is a simple example using `pd` instead, which provides everything the puts statements above provide in addition to deducing the file name, line number, class name, and method name automatically for dead-easy debugging:
7676

7777
```ruby
7878
pd order_total
@@ -353,6 +353,15 @@ unless Rails.env.development? || Rails.env.test?
353353
end
354354
```
355355
356+
The Rails `config.log_level` is assumed to be `:debug`. If you have it set to something else like `:info`, then you need to update `PutsDebuggerer.printer` to print at a different log level (e.g. `:info`) by adding the following code to the initializer above (this code is a modification of the default at `PutsDebuggerer::PRINTER_RAILS`):
357+
358+
```ruby
359+
PutsDebuggerer.printer = lambda do |output|
360+
puts output if Rails.env.test?
361+
Rails.logger.info(output)
362+
end
363+
```
364+
356365
### Option 2: Manual
357366

358367
Or manually install and require library.
@@ -418,7 +427,7 @@ Output:
418427
=> "Beatles"
419428
```
420429

421-
In addition to the object/expression output, you get to see the source file name, line number, invoked class method, and source code to help you debug and troubleshoot problems quicker (it even works in IRB).
430+
In addition to the object/expression output, you get to see the source file name, line number, class name, method name, and source code to help you debug and troubleshoot problems quicker (it even works in IRB).
422431

423432
You can use `pd` at the top-level main object too, and it prings `Object.<main>` for the class/method.
424433

@@ -831,7 +840,7 @@ Prints out the following in standard out stream only (not in log files):
831840
832841
Print engine is similar to `printer`, except it is focused on the scope of formatting
833842
the data object being printed (excluding metadata such as file name, line number,
834-
invoked class method, and expression, which are handled by the `printer`).
843+
class name, method name, and expression, which are handled by the `printer`).
835844
As such, it is also a global method symbol or lambda expression.
836845
Examples of global methods are `:p`, `:ap`, and `:pp`.
837846
An example of a lambda expression is `lambda {|object| puts object.to_a.join(" | ")}`

Rakefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ Jeweler::Tasks.new do |gem|
1717
gem.name = "puts_debuggerer"
1818
gem.homepage = "http://github.com/AndyObtiva/puts_debuggerer"
1919
gem.license = "MIT"
20-
gem.summary = %Q{Ruby library for improved puts debugging, automatically displaying bonus useful information such as source file name, line number, invoked class method, and source code.}
20+
gem.summary = %Q{Ruby library for improved puts debugging, automatically displaying bonus useful information such as source file name, line number, class name, method name, and source code.}
2121
gem.description = <<-MULTI
2222
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.
23-
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, invoked class methods, code statements, and formats output nicely courtesy of awesome_print.
23+
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 file names, line numbers, classes, and methods contained the puts statements, 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, class names, method names, and code statements; and formats output nicely courtesy of awesome_print.
2424
Partially inspired by this blog post: https://tenderlovemaking.com/2016/02/05/i-am-a-puts-debuggerer.html (Credit to Tenderlove.)
2525
MULTI
2626
gem.email = "[email protected]"

TODO.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ Here are tasks considered for future versions. Once done, they are moved to the
55
## Next
66

77
- Fix issue with attempting to modify a frozen hash when passed as value for `pd` command (check if frozen)
8+
- Enable easier setting of the `pd` log level for a Rails application than requiring a `PutsDebuggerer.printer` lambda by offering the option `PutsDebuggerer.log_level`.
89
- When using last arg as hash for options, leave out options that are not puts_debuggerer-specific for printing out
910
- Support displaying the date/time of the pd printout via an option (local and global)
11+
- Display class#method for instance methods and class::method for class methods
1012
- Consider supporting `header: :method` to print the Class#method name as the header (consider supporting in footer/wrapper too)
1113
- Consider adding performance profiling to pd methods automatically, with some customization options too
1214
- Fix issue with no printing code in bigger rails apps filled with other gems (perhaps there is some conflict?)
@@ -16,7 +18,7 @@ Here are tasks considered for future versions. Once done, they are moved to the
1618
- Have `caller` printing in Glimmer DSL for Opal print one statement per line
1719
- Support header: 30 to customize the length of the header (and do the same for footer and wrapper)
1820
- Support header: '#' to customize the character of the header (and do the same for footer and wrapper)
19-
- h: true and f: true alternatives for header and footer (as well as other ideas to shorten)
21+
- :h and :f alternatives for header and footer (as well as other ideas to shorten)
2022
- Support `methods: true` to print unique methods not on Object or `methods: :all`, automatically sorted
2123
- Consider making header use >>> and footer <<< instead of * for better findability.
2224
- Provide option to set a logger as printer without hooking formatter unto logger

puts_debuggerer.gemspec

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ Gem::Specification.new do |s|
1111
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
1212
s.require_paths = ["lib".freeze]
1313
s.authors = ["Andy Maleh".freeze]
14-
s.date = "2024-05-31"
15-
s.description = "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.\nIn 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, invoked class methods, code statements, and formats output nicely courtesy of awesome_print.\nPartially inspired by this blog post: https://tenderlovemaking.com/2016/02/05/i-am-a-puts-debuggerer.html (Credit to Tenderlove.)\n".freeze
14+
s.date = "2024-06-04"
15+
s.description = "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.\nIn 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 file names, line numbers, classes, and methods contained the puts statements, 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, class names, method names, and code statements; and formats output nicely courtesy of awesome_print.\nPartially inspired by this blog post: https://tenderlovemaking.com/2016/02/05/i-am-a-puts-debuggerer.html (Credit to Tenderlove.)\n".freeze
1616
s.email = "[email protected]".freeze
1717
s.extra_rdoc_files = [
1818
"CHANGELOG.md",
@@ -34,7 +34,7 @@ Gem::Specification.new do |s|
3434
s.homepage = "http://github.com/AndyObtiva/puts_debuggerer".freeze
3535
s.licenses = ["MIT".freeze]
3636
s.rubygems_version = "3.5.3".freeze
37-
s.summary = "Ruby library for improved puts debugging, automatically displaying bonus useful information such as source file name, line number, invoked class method, and source code.".freeze
37+
s.summary = "Ruby library for improved puts debugging, automatically displaying bonus useful information such as source file name, line number, class name, method name, and source code.".freeze
3838

3939
s.specification_version = 4
4040

0 commit comments

Comments
 (0)