Skip to content

Commit 860bbd4

Browse files
committed
Add pry() function from hunner-pry
1 parent 96af506 commit 860bbd4

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

README.markdown

+14
Original file line numberDiff line numberDiff line change
@@ -851,6 +851,20 @@ For example:
851851

852852
*Type*: rvalue.
853853

854+
#### `pry`
855+
856+
This function invokes a pry debugging session in the current scope object. This is useful for debugging manifest code at specific points during a compilation. Should only be used when running `puppet apply` or running a puppet master in the foreground. This requires the `pry` gem to be installed in puppet's rubygems.
857+
858+
*Examples:*
859+
```puppet
860+
pry()
861+
```
862+
Once in a pry session, some interesting commands:
863+
864+
* Run `catalog` to see the contents currently compiling catalog
865+
* Run `cd catalog` and `ls` to see catalog methods and instance variables
866+
* Run `@resource_table` to see the current catalog resource table
867+
854868
#### `assert_private`
855869

856870
Sets the current class or definition as private. Calling the class or definition from outside the current module will fail.

lib/puppet/parser/functions/pry.rb

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#
2+
# pry.rb
3+
#
4+
5+
module Puppet::Parser::Functions
6+
newfunction(:pry, :type => :statement, :doc => <<-EOS
7+
This function invokes a pry debugging session in the current scope object. This is useful for debugging manifest code at specific points during a compilation.
8+
9+
*Examples:*
10+
11+
pry()
12+
EOS
13+
) do |arguments|
14+
begin
15+
require 'pry'
16+
rescue LoadError
17+
raise(Puppet::Error, "pry(): Requires the 'pry' rubygem to use, but it was not found")
18+
end
19+
#
20+
## Run `catalog` to see the contents currently compiling catalog
21+
## Run `cd catalog` and `ls` to see catalog methods and instance variables
22+
## Run `@resource_table` to see the current catalog resource table
23+
#
24+
if $stdout.isatty
25+
binding.pry # rubocop:disable Lint/Debugger
26+
else
27+
Puppet.warning 'pry(): cowardly refusing to start the debugger on a daemonized master'
28+
end
29+
end
30+
end

0 commit comments

Comments
 (0)