Skip to content
🔍Help you get reading the huge open souce libraries in Ruby and trace its source locations
Ruby Shell
Branch: master
Clone or download
yhirano55 Merge pull request #17 from okuramasafumi/patch-1
Print to stderr instead of stdout when error occurs
Latest commit 1b73483 Aug 6, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
bin First implement May 1, 2019
examples Add examples Jun 7, 2019
lib Print to stderr instead of stdout when error occurs Aug 6, 2019
spec Add abbr format for markdown Jul 31, 2019
.gitignore init May 1, 2019
.rspec
.rubocop.yml Fix rubocop warnings Jul 31, 2019
.travis.yml Fix version Jul 5, 2019
Gemfile Add rubocop May 1, 2019
Gemfile.lock Bump v0.9.6 Aug 1, 2019
LICENSE.txt init May 1, 2019
README.md Add abbr format for markdown Jul 31, 2019
Rakefile First implement May 1, 2019
trace_location.gemspec Fix ruby version Jul 5, 2019

README.md

TraceLocation

TraceLocation helps you get tracing the source location of codes, and helps you can get reading the huge open souce libraries in Ruby.

Installation

Add this line to your application's Gemfile:

gem 'trace_location'

And then execute:

$ bundle

Or install it yourself as:

$ gem install trace_location

Usage

Example: Track establish connection in Active Record

config = Rails.application.config.database_configuration[Rails.env]

TraceLocation.trace do
  # You just surround you want to track the process.
  ActiveRecord::Base.establish_connection(config)
end

Then you can get logs like this: .md, .log, .csv

Trace method options

name content example
format :md, :log, :csv (default: :md) :md
match Regexp, Symbol, String or Array for allow list [:activerecord, :activesupport]
ignore Regexp, Symbol, String or Array for deny list /bootsnap|activesupport/

More examples

Example: Track the validation process of Active Record

book = Book.new(title: "My Book Title")
TraceLocation.trace(match: /activerecord/) { book.validate }

Results: .md, .log, .csv

Example: Track the lifecycle of Rails application

env = Rack::MockRequest.env_for('http://localhost:3000/books')

TraceLocation.trace do
  status, headers, body = Rails.application.call(env)
end

Results: .md, .log, .csv

Example: Track the has_secure_password in User model

class User < ApplicationRecord
  # temporary surrounding with TraceLocation#trace
  TraceLocation.trace(format: :md, ignore: /activesupport/) do
    has_secure_password
  end

Results: .md, .log, .csv

Example: Track the rendering process of action in controller class

class BooksController < ApplicationController
  before_action :set_book, only: [:show, :update, :destroy]

  # GET /books
  def index
    @books = Book.all

    # temporary surrounding with TraceLocation#trace
    TraceLocation.trace(format: :md, ignore: /activesupport|rbenv|concurrent-ruby/) do
      render json: @books
    end
  end

Results: .md, .log, .csv

License

MIT License

You can’t perform that action at this time.