Skip to content

Commit a2cf0e5

Browse files
committed
Fix issue with deleting pd options from a Hash if it was the only argument breaking the guarantee that pd never modifies the printed object, which could cause bugs. / Fix issue with attempting to modify a frozen Hash when passing a frozen Hash as the only argument for pd method
1 parent 80d4be6 commit a2cf0e5

File tree

8 files changed

+31
-20
lines changed

8 files changed

+31
-20
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Change Log
22

3+
## 1.0.1
4+
5+
- Fix issue with deleting `pd` options from a `Hash` if it was the only argument breaking the guarantee that `pd` never modifies the printed object, which could cause bugs.
6+
- Fix issue with attempting to modify a frozen `Hash` when passing a frozen `Hash` as the only argument for `pd` method
7+
38
## 1.0.0
49

510
- Support including class/method after file/line in every `pd` printout

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Puts Debuggerer 1.0.0
1+
# Puts Debuggerer 1.0.1
22
## Debugger-less Debugging FTW
33
## [Featured in State of the Art Rails 2023 Edition](https://github.com/DanielVartanov/state-of-the-art-rails/tree/bd7a509f5f0ab07cebfeada779b5c73e1eaf22ed)
44
[![Gem Version](https://badge.fury.io/rb/puts_debuggerer.svg)](http://badge.fury.io/rb/puts_debuggerer)
@@ -332,7 +332,7 @@ This is the recommended way for installing in [Rails](rubyonrails.org) apps in a
332332
Add the following to bundler's `Gemfile` (in Rails, you can optionally limit to the `:development` and `:test` groups).
333333

334334
```ruby
335-
gem 'puts_debuggerer', '~> 1.0.0'
335+
gem 'puts_debuggerer', '~> 1.0.1'
336336
```
337337

338338
Run:
@@ -367,7 +367,7 @@ end
367367
Or manually install and require library.
368368

369369
```bash
370-
gem install puts_debuggerer -v1.0.0
370+
gem install puts_debuggerer -v1.0.1
371371
```
372372

373373
```ruby

TODO.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ Here are tasks considered for future versions. Once done, they are moved to the
44

55
## Next
66

7-
- 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`.
97
- When using last arg as hash for options, leave out options that are not puts_debuggerer-specific for printing out
108
- Support displaying the date/time of the pd printout via an option (local and global)
119
- Display class#method for instance methods and class::method for class methods
@@ -39,3 +37,4 @@ Here are tasks considered for future versions. Once done, they are moved to the
3937
- Highlight the pd being printed if multiple pds exist in the same line (perhaps by calling .red on its string reusing that from ap)
4038
- Have pd support running from JAR files in JRuby
4139
- Fix issue with using SimpleDelegator, which seems to break puts_debuggerer output for the class that inherits from it
40+
- 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`.

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.0.0
1+
1.0.1

lib/puts_debuggerer.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -484,9 +484,7 @@ def determine_options(objects)
484484
convert_options(objects.delete_at(-1))
485485
elsif objects.size == 1 && objects.first.is_a?(Hash)
486486
hash = objects.first
487-
convert_options(hash.slice(*OPTIONS).tap do
488-
hash.delete_if {|option| OPTIONS.include?(option)}
489-
end)
487+
convert_options(hash.slice(*OPTIONS))
490488
end
491489
end
492490

puts_debuggerer.gemspec

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22
# DO NOT EDIT THIS FILE DIRECTLY
33
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
44
# -*- encoding: utf-8 -*-
5-
# stub: puts_debuggerer 1.0.0 ruby lib
5+
# stub: puts_debuggerer 1.0.1 ruby lib
66

77
Gem::Specification.new do |s|
88
s.name = "puts_debuggerer".freeze
9-
s.version = "1.0.0".freeze
9+
s.version = "1.0.1".freeze
1010

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-06-04"
14+
s.date = "2024-06-28"
1515
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 = "andy.am@gmail.com".freeze
1717
s.extra_rdoc_files = [

spec/lib/puts_debuggerer__with_piecemeal_options__spec.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@
1717
it 'supports enabling header per single puts' do
1818
PutsDebuggererInvoker.dynamic_nested_array(header: true) # support options alone
1919
output = $stdout.string
20-
expect(output).to eq("#{PutsDebuggerer::HEADER_DEFAULT}\n[PD] #{puts_debuggerer_invoker_file}:26 in PutsDebuggererInvoker.dynamic_nested_array\n > pd *array_including_options\n => {}\n")
20+
expect(output).to eq("#{PutsDebuggerer::HEADER_DEFAULT}\n[PD] #{puts_debuggerer_invoker_file}:26 in PutsDebuggererInvoker.dynamic_nested_array\n > pd *array_including_options\n => {:header=>true}\n")
2121
$stdout = StringIO.new
2222
PutsDebuggererInvoker.dynamic_nested_array([1, [2, 3]], header: true)
2323
output = $stdout.string
2424
expect(output).to eq("#{PutsDebuggerer::HEADER_DEFAULT}\n[PD] #{puts_debuggerer_invoker_file}:26 in PutsDebuggererInvoker.dynamic_nested_array\n > pd *array_including_options\n => [1, [2, 3]]\n")
2525
$stdout = StringIO.new
2626
PutsDebuggererInvoker.dynamic_nested_array(name: 'Sean', header: true) # support hash including options
2727
output = $stdout.string
28-
expect(output).to eq("#{PutsDebuggerer::HEADER_DEFAULT}\n[PD] #{puts_debuggerer_invoker_file}:26 in PutsDebuggererInvoker.dynamic_nested_array\n > pd *array_including_options\n => {:name=>\"Sean\"}\n")
28+
expect(output).to eq("#{PutsDebuggerer::HEADER_DEFAULT}\n[PD] #{puts_debuggerer_invoker_file}:26 in PutsDebuggererInvoker.dynamic_nested_array\n > pd *array_including_options\n => {:name=>\"Sean\", :header=>true}\n")
2929
$stdout = StringIO.new
3030
PutsDebuggererInvoker.dynamic_nested_array([1, [2, 3]])
3131
output = $stdout.string
@@ -34,15 +34,15 @@
3434
it 'supports enabling header per single puts using shortcut syntax' do
3535
PutsDebuggererInvoker.dynamic_nested_array(h: :t) # support options alone
3636
output = $stdout.string
37-
expect(output).to eq("#{PutsDebuggerer::HEADER_DEFAULT}\n[PD] #{puts_debuggerer_invoker_file}:26 in PutsDebuggererInvoker.dynamic_nested_array\n > pd *array_including_options\n => {}\n")
37+
expect(output).to eq("#{PutsDebuggerer::HEADER_DEFAULT}\n[PD] #{puts_debuggerer_invoker_file}:26 in PutsDebuggererInvoker.dynamic_nested_array\n > pd *array_including_options\n => {:h=>:t}\n")
3838
$stdout = StringIO.new
3939
PutsDebuggererInvoker.dynamic_nested_array([1, [2, 3]], h: :t)
4040
output = $stdout.string
4141
expect(output).to eq("#{PutsDebuggerer::HEADER_DEFAULT}\n[PD] #{puts_debuggerer_invoker_file}:26 in PutsDebuggererInvoker.dynamic_nested_array\n > pd *array_including_options\n => [1, [2, 3]]\n")
4242
$stdout = StringIO.new
4343
PutsDebuggererInvoker.dynamic_nested_array(name: 'Sean', h: :t) # support hash including options
4444
output = $stdout.string
45-
expect(output).to eq("#{PutsDebuggerer::HEADER_DEFAULT}\n[PD] #{puts_debuggerer_invoker_file}:26 in PutsDebuggererInvoker.dynamic_nested_array\n > pd *array_including_options\n => {:name=>\"Sean\"}\n")
45+
expect(output).to eq("#{PutsDebuggerer::HEADER_DEFAULT}\n[PD] #{puts_debuggerer_invoker_file}:26 in PutsDebuggererInvoker.dynamic_nested_array\n > pd *array_including_options\n => {:name=>\"Sean\", :h=>:t}\n")
4646
$stdout = StringIO.new
4747
PutsDebuggererInvoker.dynamic_nested_array([1, [2, 3]])
4848
output = $stdout.string
@@ -51,15 +51,15 @@
5151
it 'supports enabling footer per single puts' do
5252
PutsDebuggererInvoker.dynamic_nested_array(footer: true) # support options alone
5353
output = $stdout.string
54-
expect(output).to eq("[PD] #{puts_debuggerer_invoker_file}:26 in PutsDebuggererInvoker.dynamic_nested_array\n > pd *array_including_options\n => {}\n#{PutsDebuggerer::FOOTER_DEFAULT}\n")
54+
expect(output).to eq("[PD] #{puts_debuggerer_invoker_file}:26 in PutsDebuggererInvoker.dynamic_nested_array\n > pd *array_including_options\n => {:footer=>true}\n#{PutsDebuggerer::FOOTER_DEFAULT}\n")
5555
$stdout = StringIO.new
5656
PutsDebuggererInvoker.dynamic_nested_array([1, [2, 3]], footer: true)
5757
output = $stdout.string
5858
expect(output).to eq("[PD] #{puts_debuggerer_invoker_file}:26 in PutsDebuggererInvoker.dynamic_nested_array\n > pd *array_including_options\n => [1, [2, 3]]\n#{PutsDebuggerer::FOOTER_DEFAULT}\n")
5959
$stdout = StringIO.new
6060
PutsDebuggererInvoker.dynamic_nested_array(name: 'Sean', footer: true) # support hash including options
6161
output = $stdout.string
62-
expect(output).to eq("[PD] #{puts_debuggerer_invoker_file}:26 in PutsDebuggererInvoker.dynamic_nested_array\n > pd *array_including_options\n => {:name=>\"Sean\"}\n#{PutsDebuggerer::FOOTER_DEFAULT}\n")
62+
expect(output).to eq("[PD] #{puts_debuggerer_invoker_file}:26 in PutsDebuggererInvoker.dynamic_nested_array\n > pd *array_including_options\n => {:name=>\"Sean\", :footer=>true}\n#{PutsDebuggerer::FOOTER_DEFAULT}\n")
6363
$stdout = StringIO.new
6464
PutsDebuggererInvoker.dynamic_nested_array([1, [2, 3]])
6565
output = $stdout.string
@@ -68,15 +68,15 @@
6868
it 'supports enabling footer per single puts using shortcut syntax' do
6969
PutsDebuggererInvoker.dynamic_nested_array(f: :t) # support options alone
7070
output = $stdout.string
71-
expect(output).to eq("[PD] #{puts_debuggerer_invoker_file}:26 in PutsDebuggererInvoker.dynamic_nested_array\n > pd *array_including_options\n => {}\n#{PutsDebuggerer::FOOTER_DEFAULT}\n")
71+
expect(output).to eq("[PD] #{puts_debuggerer_invoker_file}:26 in PutsDebuggererInvoker.dynamic_nested_array\n > pd *array_including_options\n => {:f=>:t}\n#{PutsDebuggerer::FOOTER_DEFAULT}\n")
7272
$stdout = StringIO.new
7373
PutsDebuggererInvoker.dynamic_nested_array([1, [2, 3]], f: :t)
7474
output = $stdout.string
7575
expect(output).to eq("[PD] #{puts_debuggerer_invoker_file}:26 in PutsDebuggererInvoker.dynamic_nested_array\n > pd *array_including_options\n => [1, [2, 3]]\n#{PutsDebuggerer::FOOTER_DEFAULT}\n")
7676
$stdout = StringIO.new
7777
PutsDebuggererInvoker.dynamic_nested_array(name: 'Sean', f: :t) # support hash including options
7878
output = $stdout.string
79-
expect(output).to eq("[PD] #{puts_debuggerer_invoker_file}:26 in PutsDebuggererInvoker.dynamic_nested_array\n > pd *array_including_options\n => {:name=>\"Sean\"}\n#{PutsDebuggerer::FOOTER_DEFAULT}\n")
79+
expect(output).to eq("[PD] #{puts_debuggerer_invoker_file}:26 in PutsDebuggererInvoker.dynamic_nested_array\n > pd *array_including_options\n => {:name=>\"Sean\", :f=>:t}\n#{PutsDebuggerer::FOOTER_DEFAULT}\n")
8080
$stdout = StringIO.new
8181
PutsDebuggererInvoker.dynamic_nested_array([1, [2, 3]])
8282
output = $stdout.string

spec/lib/puts_debuggerer_spec.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,15 @@ def full_message
6767
output = $stdout.string
6868
expect(output).to eq("")
6969
end
70+
71+
it 'prints frozen hash' do
72+
hash = {a: 1, b: 2, c: 3, h: :t, f: :t}.freeze
73+
result = PutsDebuggererInvoker.call_pd(hash)
74+
# TODO it is odd we are getting the PutsDebuggerInvoker file, but the Array class. See if we should fix something here.
75+
expect(result).to eq(hash)
76+
output = $stdout.string
77+
expect(output).to eq(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n[PD] /Users/andymaleh/code/puts_debuggerer/spec/support/puts_debuggerer_invoker.rb:60 in PutsDebuggererInvoker.call_pd\n > pd *args\n => {:a=>1, :b=>2, :c=>3, :h=>:t, :f=>:t}\n<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n")
78+
end
7079

7180
context 'look into puts debuggerer blog post by tenderlove for other goodies to add'
7281
context 'deadlock detection support'

0 commit comments

Comments
 (0)