module AwesomePrint::Puppet
Public Class Methods
included(base)
click to toggle source
# File lib/awesome_print/ext/awesome_puppet.rb, line 19 def self.included(base) base.send :alias_method, :cast_without_puppet_resource, :cast base.send :alias_method, :cast, :cast_with_puppet_resource end
Public Instance Methods
awesome_bolt_type(object)
click to toggle source
# File lib/awesome_print/ext/awesome_puppet.rb, line 43 def awesome_bolt_type(object) if object.class.to_s.include?('Result') object.to_data.ai elsif object.is_a?(::Bolt::Target) object.to_h.merge(object.detail).ai else object.ai end end
awesome_puppet_resource(object)
click to toggle source
# File lib/awesome_print/ext/awesome_puppet.rb, line 53 def awesome_puppet_resource(object) return '' if object.nil? resource_object = object.to_ral awesome_puppet_type(resource_object) end
awesome_puppet_type(object)
click to toggle source
# File lib/awesome_print/ext/awesome_puppet.rb, line 60 def awesome_puppet_type(object) return '' if object.nil? return object.to_s unless object.respond_to?(:name) && object.respond_to?(:title) && object.respond_to?(:to_hash) h = if [].respond_to?(:to_h) # to_h is only supported in ruby 2.1+ object.to_hash.merge(name: object.name, title: object.title).sort.to_h else object.to_hash.merge(name: object.name, title: object.title) end res_str = awesome_hash(JSON.parse(h.to_json)) # converting to json removes symbols "#{object.class} #{res_str}" end
cast_with_puppet_resource(object, type)
click to toggle source
this tells ap how to cast our object so we can be specific about printing different puppet objects
# File lib/awesome_print/ext/awesome_puppet.rb, line 26 def cast_with_puppet_resource(object, type) cast = cast_without_puppet_resource(object, type) # check the object to see if it has an acestor (< ) of the specified type if defined?(::Puppet::Type) && (object.class < ::Puppet::Type) cast = :puppet_type elsif defined?(::Puppet::Pops::Types) && (object.class < ::Puppet::Pops::Types) cast = :puppet_type elsif defined?(::Puppet::Parser::Resource) && (object.class < ::Puppet::Parser::Resource) cast = :puppet_resource elsif /Puppet::Pops::Types/.match(object.class.to_s) cast = :puppet_type elsif /Bolt::/.match(object.class.to_s) cast = :bolt_type end cast end