0.02
Repository is archived
No commit activity in last 3 years
No release in over 3 years
CodeMapper is a tool to generate call graphs from your Ruby code.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.14
~> 5.0
~> 10.0

Runtime

~> 0.4
 Project Readme

CodeMapper

CodeMapper is a tool to generate call graphs from your Ruby code.

I built this tool in order to familiarize myself with new Ruby codebases. You can read all about it here.

Installation

Add this line to your application's Gemfile:

gem 'code_mapper'

And then execute:

$ bundle

Or install it yourself as:

$ gem install code_mapper

Usage

Generating a call graph and outputting as text to STDOUT:

CodeMapper.trace do
  # Code to trace
end

You can limit what classes and methods are outputted using filter:

CodeMapper.trace(filter: /^Dog\./) do
  Dog.new # will get outputted
  Cat.new # won't get outputted
end

You can also limit the tracing to a specific lexical scope using start_at:

CodeMapper.trace(filter: /^Dog\./, start_at: 'Dog.bark') do
  dog = Dog.new # won't get outputted
  dog.bark # will get outputted and all Dog.* calls made within Dog.bark
  Dog.new # won't get outputted
  Cat.new # won't get outputted
end

You can limit the depth of the call graph using max_depth:

CodeMapper.trace(max_depth: 3) do
  # Only first 3 levels will be outputted
end

By default, the call graph will be outputted as text to STDOUT.

However you can output the call graph to any IO:

CodeMapper.trace(output: CodeMapper::Output::Text.new($stderr)) do
  # Code to trace
end

CodeMapper is also capable of outputting dot graphs which can be converted to an image using graphviz:

file = File.open('graph.dot', 'w')
CodeMapper.trace(output: CodeMapper::Output::Dot.new(file)) do
  # Code to trace
end
file.close
$ dot -Tpng graph.dot > graph.png

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/cjoudrey/code_mapper. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

The gem is available as open source under the terms of the MIT License.