Sha256: 55758fd3cb14d8c12d3fab4bb7e56e8457a38528bfdedcd4c2c3bfa5f89523bf

Contents?: true

Size: 903 Bytes

Versions: 9

Compression:

Stored size: 903 Bytes

Contents

# Proc extension to get more location info out of a proc
require 'lucid/platform'
class Proc #:nodoc:
  PROC_PATTERN = /[\d\w]+@(.+):(\d+).*>/
  PWD = Dir.pwd

  def to_comment_line
    "# #{file_colon_line}"
  end

  def backtrace_line(name)
    "#{file_colon_line}:in `#{name}'"
  end

  if Proc.new{}.to_s =~ PROC_PATTERN
    def file_colon_line
      path, line = *to_s.match(PROC_PATTERN)[1..2]
      path = File.expand_path(path)
      pwd = File.expand_path(PWD)
      pwd.force_encoding(path.encoding)
      if path.index(pwd)
        path = path[pwd.length+1..-1]
      elsif path =~ /.*\/gems\/(.*\.rb)$/
        path = $1
      end
      "#{path}:#{line}"
    end
  else
    # This Ruby implementation doesn't implement Proc#to_s correctly
    STDERR.puts "*** THIS RUBY IMPLEMENTATION DOESN'T REPORT FILE AND LINE FOR PROCS ***"

    def file_colon_line
      "UNKNOWN:-1"
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
lucid-0.2.1 lib/lucid/core_ext/proc.rb
lucid-0.2.0 lib/lucid/core_ext/proc.rb
lucid-0.1.1 lib/lucid/core_ext/proc.rb
lucid-0.1.0 lib/lucid/core_ext/proc.rb
lucid-0.0.9 lib/lucid/core_ext/proc.rb
lucid-0.0.8 lib/lucid/core_ext/proc.rb
lucid-0.0.7 lib/lucid/core_ext/proc.rb
lucid-0.0.6 lib/lucid/core_ext/proc.rb
lucid-0.0.5 lib/lucid/core_ext/proc.rb