Better file/line detection in sinatra_warn

This commit is contained in:
Ryan Tomayko 2009-01-13 12:09:53 -08:00
parent 17cb177ea3
commit 4cddd70541
1 changed files with 3 additions and 1 deletions

View File

@ -10,7 +10,9 @@ require 'sinatra/main'
# Like Kernel#warn but outputs the location that triggered the warning.
def sinatra_warn(*message)
line = caller[1].sub(/:in .*/, '')
line = caller.
detect { |line| line !~ /(?:lib\/sinatra\/|__DELEGATE__)/ }.
sub(/:in .*/, '')
warn "#{line}: warning: #{message.join(' ')}"
end