Sha256: 13b1dc1ea2160c39d5924a803a0735fc789732ec316936b9605660ced729eaa8

Contents?: true

Size: 1006 Bytes

Versions: 75

Compression:

Stored size: 1006 Bytes

Contents

# frozen_string_literal: true
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)

        datum = Utils.redact(datum)
      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

75 entries across 73 versions & 3 rubygems

Version Path
excon-1.2.1 lib/excon/pretty_printer.rb
excon-1.2.0 lib/excon/pretty_printer.rb
excon-1.1.1 lib/excon/pretty_printer.rb
excon-1.1.0 lib/excon/pretty_printer.rb
excon-1.0.0 lib/excon/pretty_printer.rb
excon-0.112.0 lib/excon/pretty_printer.rb
excon-0.111.0 lib/excon/pretty_printer.rb
excon-0.110.0 lib/excon/pretty_printer.rb
excon-0.109.0 lib/excon/pretty_printer.rb
excon-0.108.0 lib/excon/pretty_printer.rb
excon-0.107.0 lib/excon/pretty_printer.rb
excon-0.106.0 lib/excon/pretty_printer.rb
excon-0.105.0 lib/excon/pretty_printer.rb
excon-0.104.0 lib/excon/pretty_printer.rb
excon-0.103.0 lib/excon/pretty_printer.rb
excon-0.102.0 lib/excon/pretty_printer.rb
excon-0.101.0 lib/excon/pretty_printer.rb
excon-0.100.0 lib/excon/pretty_printer.rb
excon-0.99.0 lib/excon/pretty_printer.rb
excon-0.98.0 lib/excon/pretty_printer.rb