Module: MessagePack::Inspect::YAMLStreamer

Defined in:
lib/msgpack/inspect/streamer.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.object(io, depth, index) ⇒ Object



35
36
37
# File 'lib/msgpack/inspect/streamer.rb', line 35

def self.object(io, depth, index)
  yield
end

.objects(io, depth) ⇒ Object



30
31
32
33
# File 'lib/msgpack/inspect/streamer.rb', line 30

def self.objects(io, depth)
  io.puts "---" if depth == 0
  yield
end

Instance Method Details

#attributes(io) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/msgpack/inspect/streamer.rb', line 70

def attributes(io)
  write(:format, :header)

  super

  write(:error) if @error

  case @format
  when :fixint, :uint8, :uint16, :uint32, :uint64, :int8, :int16, :int32, :int64
    write(:data, :value)
  when :fixmap, :map16, :map32
    write(:length)
  when :fixarray, :array16, :array32
    write(:length)
  when :fixstr, :str8, :str16, :str32
    write(:length, :data, :value)
  when :nil
    write(:data, :value)
  when :false
    write(:data, :value)
  when :true
    write(:data, :value)
  when :bin8, :bin16, :bin32
    write(:length, :data, :value)
  when :ext8, :ext16, :ext32, :fixext1, :fixext2, :fixext4, :fixext8, :fixext16
    if @value
      write(:exttype, :length, :data, :value)
    else
      write(:exttype, :length, :data)
    end
  when :float32, :float64
    write(:data, :value)
  when :never_used
    write(:data)
  end
end

#element_keyObject



117
118
119
120
# File 'lib/msgpack/inspect/streamer.rb', line 117

def element_key
  @io.puts %!#{indent}  - key:!
  super
end

#element_valueObject



122
123
124
125
# File 'lib/msgpack/inspect/streamer.rb', line 122

def element_value
  @io.puts %!#{indent}    value:!
  super
end

#elements(&block) ⇒ Object



107
108
109
110
111
112
113
114
115
# File 'lib/msgpack/inspect/streamer.rb', line 107

def elements(&block)
  if @length == 0
    @io.puts %!#{indent}children: []!
    return
  end

  @io.puts %!#{indent}children:!
  super
end

#indent(head = false) ⇒ Object



39
40
41
42
43
44
45
# File 'lib/msgpack/inspect/streamer.rb', line 39

def indent(head = false)
  if head
    "  " * (@depth - 1) + "- "
  else
    "  " * @depth
  end
end

#write(*attrs) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/msgpack/inspect/streamer.rb', line 47

def write(*attrs)
  attrs.each do |attr|
    case attr
    when :format
      @io.puts %!#{indent(@heading)}format: "#{@format.to_s}"!
    when :header
      @io.puts %!#{indent}header: "0x#{hex(@header)}"!
    when :data
      @io.puts %!#{indent}data: "0x#{@data}"!
    when :value
      if @value.nil?
        @io.puts %!#{indent}value: null!
      else
        @io.puts %!#{indent}value: #{@value.inspect}!
      end
    when :length
      @io.puts %!#{indent}length: #{@length}!
    when :exttype
      @io.puts %!#{indent}exttype: #{@exttype}!
    end
  end
end