Sha256: b5cc3bfbe7b5e4ff760b3d30cffa25d356250e7b0b63ba00876541205aa877f9

Contents?: true

Size: 1.27 KB

Versions: 3

Compression:

Stored size: 1.27 KB

Contents

module AwesomePrint
  module Puppet
    def self.included(base)
      base.send :alias_method, :cast_without_puppet_resource, :cast
      base.send :alias_method, :cast, :cast_with_puppet_resource
    end

    # this tells ap how to cast our object so we can be specific
    # about printing different puppet objects
    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
      end
      cast
    end

    def awesome_puppet_resource(object)
      return '' if object.nil?
      awesome_puppet_type(object.to_ral)
    end

    def awesome_puppet_type(object)
      return '' if object.nil?
      h = object.to_hash.merge(:name => object.name, :title => object.title)
      res_str = awesome_hash(h)
      "#{object.class} #{res_str.gsub(':', '')}"
    end
  end
end

AwesomePrint::Formatter.send(:include, AwesomePrint::Puppet)

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
puppet-repl-0.2.2 lib/awesome_print/ext/awesome_puppet.rb
puppet-repl-0.2.1 lib/awesome_print/ext/awesome_puppet.rb
puppet-repl-0.2.0 lib/awesome_print/ext/awesome_puppet.rb