Sha256: 308e7e42d80aba85bd59dcc99a604fd466ca48432e2afd4fba8f462fb33ac9b3

Contents?: true

Size: 1.66 KB

Versions: 7

Compression:

Stored size: 1.66 KB

Contents

module Padrino
  PADRINO_IGNORE_CALLERS = [
   %r{lib/padrino-.*$},         # all padrino code
   %r{/padrino-.*/(lib|bin)},   # all padrino code
   %r{/bin/padrino$},           # all padrino code
   %r{/sinatra},                # all sinatra code
   %r{lib/tilt.*\.rb$},         # all tilt code
   %r{lib/rack.*\.rb$},         # all rack code
   %r{lib/mongrel.*\.rb$},      # all mongrel code
   %r{lib/shotgun.*\.rb$},      # all shotgun lib
   %r{bin/shotgun$},            # shotgun binary
   %r{\(.*\)},                  # generated code
   %r{shoulda/context\.rb$},    # shoulda hacks
   %r{mocha/integration},       # mocha hacks
   %r{test/unit},               # test unit hacks
   %r{rake_test_loader\.rb},    # rake hacks
   %r{custom_require\.rb$},     # rubygems require hacks
   %r{active_support},          # active_support require hacks
   %r{/thor},                   # thor require hacks
  ] unless defined?(PADRINO_IGNORE_CALLERS)

  ##
  # Add rubinius (and hopefully other VM impls) ignore patterns ...
  # 
  PADRINO_IGNORE_CALLERS.concat(RUBY_IGNORE_CALLERS) if defined?(RUBY_IGNORE_CALLERS)

  ##
  # Returns the filename for the file that is the direct caller (first caller)
  # 
  def self.first_caller
    caller_files.first
  end

  ##
  # Like Kernel#caller but excluding certain magic entries and without
  # line / method information; the resulting array contains filenames only.
  # 
  def self.caller_files
    caller_locations.map { |file,line| file }
  end

  def self.caller_locations
    caller(1).
      map    { |line| line.split(/:(?=\d|in )/)[0,2] }.
      reject { |file,line| PADRINO_IGNORE_CALLERS.any? { |pattern| file =~ pattern } }
  end
end # Padrino

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
padrino-core-0.7.5 lib/padrino-core/caller.rb
padrino-core-0.7.4 lib/padrino-core/caller.rb
padrino-core-0.7.3 lib/padrino-core/caller.rb
padrino-core-0.7.2 lib/padrino-core/caller.rb
padrino-core-0.7.1 lib/padrino-core/caller.rb
padrino-core-0.7.0 lib/padrino-core/caller.rb
padrino-core-0.6.7 lib/padrino-core/caller.rb