23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/yaml-ld-2d2ba8e32d66/lib/psych/amazing_print.rb', line 23
def awesome_psych_node(object)
contents = []
contents << colorize(object.class.name.split('::').last, :class)
contents << colorize("!<#{object.tag}>", :args) if object.tag
contents << colorize("&#{object.anchor}", :args) if object.respond_to?(:anchor) && object.anchor
contents << colorize("(implicit)", :args) if object.respond_to?(:implicit) && object.implicit
contents << colorize("(implicit end)", :args) if object.respond_to?(:implicit_end) && object.implicit_end
case object
when ::Psych::Nodes::Stream
contents << awesome_array(object.children)
when ::Psych::Nodes::Document
contents << colorize('%TAG(' + object.tag_directives.flatten.join(' ') + ')', :args) unless Array(object.tag_directives).empty?
contents << colorize("version #{object.version.join('.')}", :args) if object.version
contents << awesome_array(object.children)
when ::Psych::Nodes::Sequence
style = %w(ANY BLOCK FLOW)[object.style.to_i]
contents << awesome_array(object.children)
when ::Psych::Nodes::Mapping
style = %w(ANY BLOCK FLOW)[object.style.to_i]
contents << colorize(style, :args) if object.style
contents << awesome_hash(object.children.each_slice(2).to_h)
when ::Psych::Nodes::Scalar
style = %w(ANY PLAIN SINGLE_QUOTED DOUBLE_QUOTED LITERAL FOLDED)[object.style.to_i]
contents << colorize(style, :args) if object.style
contents << colorize("(plain)", :args) if object.plain
contents << colorize("(quoted)", :args) if object.quoted
contents << awesome_simple(object.value.inspect, :variable)
when ::Psych::Nodes::Alias
else
"Unknown node type: #{object.inspect}"
end
contents.join(' ')
end
|