RShade is a debugging/code exploration tool based on TracePoint
functionality.
Recent years I've working with relatively huge legacy code and I need a tool which can help me to figure out what is going on due execution.
Luckely Ruby have build in functionality to achieve it, but it's pretty low level. It was my motivation to create RShade
it helps me to save tons of time
when I face with something not trivial or a good start point to create dependency map when I do refactoring or bugfix. Tool still in beta and it's possible that there
is some bugs, but it's do the job.
gem install rshade
Simple wrap code that you want to check in to block and it will pretty print all of the calls which was made in this block with pointing line of executions, variables what was pass inside methods and variables what was return
RShade::Trace.reveal do
#your code here
end.show
Due that tool create a detailed log with all of the steps of execution it's hard to read (it's can easelly be 20 - 30k lines because it's shows not only your custom code but also
code in gems that are involved in execution). RShade
have filters to tackle this problem. Default filter is illiminate all code related to gems and only expose app code itself. You can
change this behaviour or add your own filter. Even when some piece of code are not shown due filtration order of calls and execution still shown in correct way.
config = ::RShade::Config.default
RShade::Trace.reveal(config) do
end.show
Filters by default represent by expression (include_path or variable_match) or (not exclude_path)
Filters can be chained like:
config = ::RShade::Config.default.include_paths { |paths| paths << /devise/ }
.exclude_paths { |paths| paths << /warden/ }
.match_variable { |name, value| name == :current_user }
paths
- is array which accept regex or string
config = ::RShade::Config.default.include_paths { |paths| paths << /devise/ }
RShade::Trace.reveal(config) do
#your code
end.show
paths
- is array which accept regex or string
config = ::RShade::Config.default.exclude_paths { |paths| paths << /devise/ }
RShade::Trace.reveal(config) do
#your code
end.show
name
- represent variable name as symbol
value
- actual variable value
config = ::RShade::Config.default.match_variable { |name, value| name == :current_user }
RShade::Trace.reveal(config) do
#your code
end.show
I've took example from https://github.com/spree/spree code base. Wrap code to take a look what code is in use when you save variant. On such huge codebase as spree it's helpful to know what callbacks are triggered and so on.
context '#cost_currency' do
context 'when cost currency is nil' do
before { variant.cost_currency = nil }
it 'populates cost currency with the default value on save' do
RShade::Trace.reveal do
variant.save!
end
expect(variant.cost_currency).to eql 'USD'
end
end
end
Below is example how output will look like. As you can see all code that have been in use is printed.
Use stack to keep connections between current method and caller
take a look on https://github.com/matugm/visual-call-graph
Bug reports and pull requests are welcome on GitHub at https://github.com/gingray/rshade.
The gem is available as open source under the terms of the MIT License.