Sha256: b5182ad7decc35d6c54f144665fa311c47e5be5638e428d2c3760ade00b64cbd

Contents?: true

Size: 966 Bytes

Versions: 22

Compression:

Stored size: 966 Bytes

Contents

#          Copyright (c) 2008 Michael Fellinger m.fellinger@gmail.com
# All files in this distribution are subject to the terms of the Ruby license.

module Ramaze

  # Gives you back the file, line and method of the caller number i
  # Example:
  #   Ramaze.caller_info(1)
  #   # => ['/usr/lib/ruby/1.8/irb/workspace.rb', '52', 'irb_binding']

  def self.caller_info(i = 1)
    file, line, meth = *parse_backtrace(caller[i])
  end

  # Parses one line of backtrace and tries to extract as much information
  # as possible.
  #
  # Example:
  #   line = "/web/repo/ramaze/lib/ramaze/dispatcher.rb:105:in `respond'"
  #   Ramaze.parse_backtrace(line)
  #   #=> ["/web/repo/ramaze/lib/ramaze/dispatcher.rb", "105", "respond"]

  def self.parse_backtrace(line = '')
    full = line.scan(/(.*?):(\d+):in `(.*?)'/).first
    return full if full and full.all?
    partial = line.scan(/(.*?):(\d+)/).first
    return partial if partial and partial.all?
    line
  end
end

Version data entries

22 entries across 22 versions & 5 rubygems

Version Path
Pistos-ramaze-2008.09 lib/ramaze/snippets/ramaze/caller_info.rb
Pistos-ramaze-2008.12 lib/ramaze/snippets/ramaze/caller_info.rb
Pistos-ramaze-2009.01 lib/ramaze/snippets/ramaze/caller_info.rb
Pistos-ramaze-2009.02 lib/ramaze/snippets/ramaze/caller_info.rb
clivecrous-ramaze-0.3.9.5 lib/ramaze/snippets/ramaze/caller_info.rb
manveru-ramaze-2008.07 lib/ramaze/snippets/ramaze/caller_info.rb
manveru-ramaze-2008.08 lib/ramaze/snippets/ramaze/caller_info.rb
manveru-ramaze-2008.09 lib/ramaze/snippets/ramaze/caller_info.rb
manveru-ramaze-2008.10 lib/ramaze/snippets/ramaze/caller_info.rb
manveru-ramaze-2008.12 lib/ramaze/snippets/ramaze/caller_info.rb
manveru-ramaze-2009.01 lib/ramaze/snippets/ramaze/caller_info.rb
ptomato-ramaze-2009.02.1 lib/ramaze/snippets/ramaze/caller_info.rb
ptomato-ramaze-2009.02 lib/ramaze/snippets/ramaze/caller_info.rb
ramaze-0.3.0 lib/ramaze/snippets/ramaze/caller_info.rb
ramaze-0.3.5 lib/ramaze/snippets/ramaze/caller_info.rb
ramaze-2008.06 lib/ramaze/snippets/ramaze/caller_info.rb
ramaze-2009.01 lib/ramaze/snippets/ramaze/caller_info.rb
ramaze-0.3.9 lib/ramaze/snippets/ramaze/caller_info.rb
ramaze-2008.11 lib/ramaze/snippets/ramaze/caller_info.rb
ramaze-0.3.9.1 lib/ramaze/snippets/ramaze/caller_info.rb