Skip to content

Add pry() function from hunner-pry #640

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 15, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -935,6 +935,20 @@ For example:

*Type*: rvalue.

#### `pry`

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.

*Examples:*
```puppet
pry()
```
Once in a pry session, some interesting commands:

* Run `catalog` to see the contents currently compiling catalog
* Run `cd catalog` and `ls` to see catalog methods and instance variables
* Run `@resource_table` to see the current catalog resource table

#### `assert_private`

Sets the current class or definition as private. Calling the class or definition from outside the current module will fail.
Expand Down
30 changes: 30 additions & 0 deletions lib/puppet/parser/functions/pry.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#
# pry.rb
#

module Puppet::Parser::Functions
newfunction(:pry, :type => :statement, :doc => <<-EOS
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.

*Examples:*

pry()
EOS
) do |arguments|
begin
require 'pry'
rescue LoadError
raise(Puppet::Error, "pry(): Requires the 'pry' rubygem to use, but it was not found")
end
#
## Run `catalog` to see the contents currently compiling catalog
## Run `cd catalog` and `ls` to see catalog methods and instance variables
## Run `@resource_table` to see the current catalog resource table
#
if $stdout.isatty
binding.pry # rubocop:disable Lint/Debugger
else
Puppet.warning 'pry(): cowardly refusing to start the debugger on a daemonized master'
end
end
end