diff options
author | Hunter Haugen <hunter@puppet.com> | 2016-08-17 10:27:54 -0700 |
---|---|---|
committer | Hunter Haugen <hunter@puppet.com> | 2016-12-08 09:41:18 -0800 |
commit | 1cd0209aec84b0135adbe6b5fc2769f0053c26f3 (patch) | |
tree | f55288ba293ac86583739642f8afe254d1adae7a | |
parent | 7507af555361b2dcba8ed6189dc54c21e64ea031 (diff) |
Add pry() function from hunner-pry
-rw-r--r-- | README.markdown | 14 | ||||
-rw-r--r-- | lib/puppet/parser/functions/pry.rb | 30 |
2 files changed, 44 insertions, 0 deletions
diff --git a/README.markdown b/README.markdown index a6b7bda..3039a2a 100644 --- a/README.markdown +++ b/README.markdown @@ -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. diff --git a/lib/puppet/parser/functions/pry.rb b/lib/puppet/parser/functions/pry.rb new file mode 100644 index 0000000..c18ef7e --- /dev/null +++ b/lib/puppet/parser/functions/pry.rb @@ -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 |