Skip to content

Commit

Permalink
Add .pryrc.rb
Browse files Browse the repository at this point in the history
  • Loading branch information
cypher committed Jun 28, 2013
1 parent 788be7d commit 01eb435
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions pryrc.rb
@@ -0,0 +1,23 @@
def write_backtrace name, backtrace, filename
exceptions = Regexp.union([
/\.bundle/,
/spec/,
/test/,
/lib\/ruby\/1.9.1/
])

backtrace.reject! { |line| line =~ exceptions }

File.open(filename, 'a') do |f|
f.write "* #{name}\n\n" + backtrace.join("\n") + "\n\n"
end
end

# Example usage:
#
# trace Redis::Client#process my_redis_calls.log
#
Pry.commands.block_command(/trace ([^ ]+) ([^ ]+)$/, "Trace a method invocation and log it to a file", :listing => "trace") do |bp, filename|
run "breakpoint #{bp} if (write_backtrace(%{#{bp}}, caller, %{#{filename}}); false)"
run "continue"
end

0 comments on commit 01eb435

Please sign in to comment.