Class: RASN2::Tracer
- Inherits:
-
Object
- Object
- RASN2::Tracer
- Defined in:
- lib/rasn2/tracer.rb
Constant Summary collapse
- TRACED_CLASSES =
[Types::Any, Types::Choice, Types::Sequence, Types::SequenceOf, Types::Base].freeze
Instance Attribute Summary collapse
- #io ⇒ IO readonly
- #tracing_level ⇒ Integer
Instance Method Summary collapse
- #color ⇒ Object
- #color=(enabled) ⇒ Object
- #colorize(str) ⇒ Object
-
#indent(level = nil) ⇒ String
Return identation for given
level. -
#initialize(io, color: false) ⇒ Tracer
constructor
A new instance of Tracer.
-
#trace(msg) ⇒ void
Puts
msgonto #io.
Constructor Details
#initialize(io, color: false) ⇒ Tracer
Returns a new instance of Tracer.
29 30 31 32 33 34 |
# File 'lib/rasn2/tracer.rb', line 29 def initialize(io, color: false) @io = io @tracing_level = 0 @rainbow = Rainbow.new @rainbow.enabled = color end |
Instance Attribute Details
#io ⇒ IO (readonly)
9 10 11 |
# File 'lib/rasn2/tracer.rb', line 9 def io @io end |
#tracing_level ⇒ Integer
11 12 13 |
# File 'lib/rasn2/tracer.rb', line 11 def tracing_level @tracing_level end |
Instance Method Details
#color ⇒ Object
13 14 15 |
# File 'lib/rasn2/tracer.rb', line 13 def color @rainbow.enabled end |
#color=(enabled) ⇒ Object
17 18 19 |
# File 'lib/rasn2/tracer.rb', line 17 def color=(enabled) @rainbow.enabled = enabled end |
#colorize(str) ⇒ Object
21 22 23 |
# File 'lib/rasn2/tracer.rb', line 21 def colorize(str) @rainbow ? @rainbow.wrap(str) : Rainbow.new.wrap(str) end |
#indent(level = nil) ⇒ String
Return identation for given level. If nil, use #tracing_level.
47 48 49 50 |
# File 'lib/rasn2/tracer.rb', line 47 def indent(level=nil) level ||= @tracing_level " " * level end |
#trace(msg) ⇒ void
This method returns an undefined value.
Puts msg onto #io.
39 40 41 42 |
# File 'lib/rasn2/tracer.rb', line 39 def trace(msg) indented = msg.split("\n").map { |line| indent + line }.join("\n") @io.puts(indented) end |