Module: TPTree
- Defined in:
- lib/tp_tree.rb,
lib/tp_tree/version.rb,
lib/tp_tree/formatter.rb,
lib/tp_tree/tree_node.rb,
lib/tp_tree/call_stack.rb,
lib/tp_tree/tree_builder.rb,
lib/tp_tree/method_filter.rb,
lib/tp_tree/interactive_viewer.rb,
lib/tp_tree/formatters/xml_formatter.rb,
lib/tp_tree/formatters/ansi_formatter.rb,
lib/tp_tree/formatters/base_formatter.rb,
lib/tp_tree/presenters/tree_node_presenter.rb
Defined Under Namespace
Modules: Formatter, Formatters, Presenters Classes: CallStack, InteractiveViewer, MethodFilter, TreeBuilder, TreeNode
Constant Summary collapse
- VERSION =
"0.1.1"
Class Method Summary collapse
-
.catch(interactive: false, write_to: nil, filter: nil, exclude: nil, &block) ⇒ Object
catch sets up a TracePoint to monitor method calls and returns, printing them in chronological order with proper tree indentation.
Class Method Details
.catch(interactive: false, write_to: nil, filter: nil, exclude: nil, &block) ⇒ Object
catch sets up a TracePoint to monitor method calls and returns, printing them in chronological order with proper tree indentation.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/tp_tree.rb', line 16 def catch(interactive: false, write_to: nil, filter: nil, exclude: nil, &block) filter_obj = MethodFilter.new(filter: filter, exclude: exclude) if filter || exclude events = TreeBuilder.new(method_filter: filter_obj, &block).build if interactive require_relative "tp_tree/interactive_viewer" InteractiveViewer.new(events).show elsif write_to require 'json' require 'time' json_data = { version: TPTree::VERSION, timestamp: Time.now.strftime('%Y-%m-%dT%H:%M:%S%z'), events: events.map(&:to_hash) } File.write(write_to, JSON.pretty_generate(json_data)) puts "Trace data written to: #{write_to}" else events.each { |event| puts event } end end |