Sha256: 7d65acbf405498c80b4183e591ddff29e323f033b485d35d580ceae2beb616f9

Contents?: true

Size: 1.19 KB

Versions: 2

Compression:

Stored size: 1.19 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)
      if (defined?(::Puppet::Type)) && (object.is_a?(::Puppet::Type))
        cast = :puppet_type
      elsif (defined?(::Puppet::Pops::Types)) && (object.is_a?(::Puppet::Pops::Types))
        cast = :puppet_type  
      elsif (defined?(::Puppet::Parser::Resource)) && (object.is_a?(::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

2 entries across 2 versions & 1 rubygems

Version Path
puppet-repl-0.1.1 lib/awesome_print/ext/awesome_puppet.rb
puppet-repl-0.1.0 lib/awesome_print/ext/awesome_puppet.rb