Embed presentation
Download to read offline







![Collecting information
config/initializers/trace_views.rb
def metric_name(path)
path.sub(/A#{Rails.root}//, '')
end
%w(render_template.action_view render_partial.action_view).map do |event_name|
ActiveSupport::Notifications.subscribe(event_name) do |*data|
event = ActiveSupport::Notifications::Event.new(*data)
template_name = metric_name(event.payload[:identifier])
UsedView.find_or_create_by_template_name(template_name)
end
end](https://image.slidesharecdn.com/findingunusedcodeinyourrailsapp-160607061431/85/Finding-unused-code-in-your-Rails-app-8-320.jpg)




This document discusses finding unused code in a Rails application. It provides two approaches: using Active Support Instrumentation to track which view templates and controller actions are rendered, and Coverband, a Rack middleware that measures production code usage. The Active Support approach subscribes to render events to record used templates and controller methods, while Coverband can directly measure unused lines of code in production.







![Collecting information
config/initializers/trace_views.rb
def metric_name(path)
path.sub(/A#{Rails.root}//, '')
end
%w(render_template.action_view render_partial.action_view).map do |event_name|
ActiveSupport::Notifications.subscribe(event_name) do |*data|
event = ActiveSupport::Notifications::Event.new(*data)
template_name = metric_name(event.payload[:identifier])
UsedView.find_or_create_by_template_name(template_name)
end
end](https://image.slidesharecdn.com/findingunusedcodeinyourrailsapp-160607061431/85/Finding-unused-code-in-your-Rails-app-8-320.jpg)



