Puppet Function: simplib::debug::inspect
- Defined in:
- lib/puppet/functions/simplib/debug/inspect.rb
- Function type:
- Ruby 4.x API
Overview
Prints out Puppet warning messages that display the passed variable, data type, and location.
WARNING: Uses EXPERIMENTAL features from Puppet, may break at any time.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/puppet/functions/simplib/debug/inspect.rb', line 5 Puppet::Functions.create_function(:'simplib::debug::inspect', Puppet::Functions::InternalFunction) do # @param to_inspect # The parameter that you wish to inspect # # @param print # Whether or not to print to the visual output # # @return [Hash] # Hash of the data that is printed dispatch :inspect do scope_param() required_param 'NotUndef', :to_inspect optional_param 'Boolean', :print end def inspect(scope, to_inspect, print=true) data = { :type => to_inspect.class, :content => to_inspect.to_pson } if scope data[:scope] = scope.to_s if scope.source data[:module_name] = scope.source.module_name data[:file] = scope.source.file data[:line] = scope.source.line end end if print msg = [ 'Simplib::Debug::Inspect:', "Type => '#{data[:type]}'", "Content => '#{data[:content]}'" ] if data[:module_name] && !data[:module_name].empty? msg << "Module: '#{data[:module_name]}'" end if data[:file] msg << "Location: '#{data[:file]}:#{data[:line]}'" end if data[:scope] msg << "Scope: '#{data[:scope]}'" end msg = msg.join(' ') # This is only required when rspec is loaded if defined?(RSpec) $stderr.puts(msg) end Puppet.warning(msg) end return data end end |