Skip to content

Commit 0d6df4f

Browse files
authored
Merge pull request #640 from hunner/add_pry
Add pry() function from hunner-pry
2 parents 5524451 + 1cd0209 commit 0d6df4f

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
@@ -944,6 +944,20 @@ For example:
944944

945945
*Type*: rvalue.
946946

947+
#### `pry`
948+
949+
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.
950+
951+
*Examples:*
952+
```puppet
953+
pry()
954+
```
955+
Once in a pry session, some interesting commands:
956+
957+
* Run `catalog` to see the contents currently compiling catalog
958+
* Run `cd catalog` and `ls` to see catalog methods and instance variables
959+
* Run `@resource_table` to see the current catalog resource table
960+
947961
#### `assert_private`
948962

949963
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)