Sha256: 85e1348d1dc4d6bc2611eefbca479d8fd1c2a6042b7ad9764116972bd5e85d89

Contents?: true

Size: 705 Bytes

Versions: 23

Compression:

Stored size: 705 Bytes

Contents

# frozen_string_literal: true

require_relative "visitor"

module Gem::SafeMarshal
  module Visitors
    class StreamPrinter < Visitor
      def initialize(io, indent: "")
        @io = io
        @indent = indent
        @level = 0
      end

      def visit(target)
        @io.write("#{@indent * @level}#{target.class}")
        target.instance_variables.each do |ivar|
          value = target.instance_variable_get(ivar)
          next if Elements::Element === value || Array === value
          @io.write(" #{ivar}=#{value.inspect}")
        end
        @io.write("\n")
        begin
          @level += 1
          super
        ensure
          @level -= 1
        end
      end
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
rubygems-update-3.5.2 lib/rubygems/safe_marshal/visitors/stream_printer.rb
rubygems-update-3.5.1 lib/rubygems/safe_marshal/visitors/stream_printer.rb
rubygems-update-3.5.0 lib/rubygems/safe_marshal/visitors/stream_printer.rb