Sha256: 9252d387db24af9baa34f305b21012eebcf88bb23e2236122e4ed5af71be9adb

Contents?: true

Size: 1.19 KB

Versions: 39

Compression:

Stored size: 1.19 KB

Contents

module Excon
  class PrettyPrinter
    def self.pp(io, datum, indent=0)
      datum = datum.dup

      # reduce duplication/noise of output
      unless datum.is_a?(Excon::Headers)
        datum.delete(:connection)
        datum.delete(:stack)

        if datum.has_key?(:headers) && datum[:headers].has_key?('Authorization')
          datum[:headers] = datum[:headers].dup
          datum[:headers]['Authorization'] = REDACTED
        end

        if datum.has_key?(:password)
          datum[:password] = REDACTED
        end
      end

      indent += 2
      max_key_length = datum.keys.map {|key| key.inspect.length}.max
      datum.keys.sort_by {|key| key.to_s}.each do |key|
        value = datum[key]
        io.write("#{' ' * indent}#{key.inspect.ljust(max_key_length)} => ")
        case value
        when Array
          io.puts("[")
          value.each do |v|
            io.puts("#{' ' * indent}  #{v.inspect}")
          end
          io.write("#{' ' * indent}]")
        when Hash
          io.puts("{")
          self.pp(io, value, indent)
          io.write("#{' ' * indent}}")
        else
          io.write("#{value.inspect}")
        end
        io.puts
      end
      indent -= 2
    end
  end
end

Version data entries

39 entries across 39 versions & 4 rubygems

Version Path
excon-0.51.0 lib/excon/pretty_printer.rb
excon-0.50.1 lib/excon/pretty_printer.rb
excon-0.50.0 lib/excon/pretty_printer.rb
able-neo4j-1.0.0 vendor/bundle/jruby/1.9/gems/excon-0.45.4/lib/excon/pretty_printer.rb
excon-0.49.0 lib/excon/pretty_printer.rb
excon-0.48.0 lib/excon/pretty_printer.rb
excon-0.47.0 lib/excon/pretty_printer.rb
excon-0.46.0 lib/excon/pretty_printer.rb
framed_rails-0.2.0 vendor/gems/excon-0.45.3/lib/excon/pretty_printer.rb
framed_rails-0.1.7 vendor/gems/excon-0.45.3/lib/excon/pretty_printer.rb
vagrant-cloudstack-1.2.0 vendor/bundle/gems/excon-0.45.4/lib/excon/pretty_printer.rb
framed_rails-0.1.5 vendor/gems/excon-0.45.3/lib/excon/pretty_printer.rb
framed_rails-0.1.4 vendor/gems/excon-0.45.3/lib/excon/pretty_printer.rb
framed_rails-0.1.3 vendor/gems/excon-0.45.3/lib/excon/pretty_printer.rb
framed_rails-0.1.2 vendor/gems/excon-0.45.3/lib/excon/pretty_printer.rb
framed_rails-0.1.0 vendor/gems/excon-0.45.3/lib/excon/pretty_printer.rb
excon-0.45.4 lib/excon/pretty_printer.rb
vagrant-cloudstack-1.1.0 vendor/bundle/gems/excon-0.45.3/lib/excon/pretty_printer.rb
excon-0.45.3 lib/excon/pretty_printer.rb
excon-0.45.2 lib/excon/pretty_printer.rb