Module: LinkifyErrors

Defined in:
lib/linkify_errors.rb,
lib/linkify_errors/version.rb

Constant Summary collapse

PROTOCOL =
"editfile"
VERSION =
"0.0.1"

Class Method Summary collapse

Class Method Details

.linkify(str) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/linkify_errors.rb', line 24

def self.linkify(str)
  file, line, desc = str.split(':')
  
  if file[0..0] == "/"
    # we already have an absolute path. We're good!
  elsif file =~ /(.*) \((.*)\) (.*)/
    # This is a part-of-rails gem, e.g. "actionpack (3.1.0.beta1) lib/action_controller/....."
    gemspecs = Gem.source_index.find_name($1)
    version_in_use = gemspecs.find {|gemspec| gemspec.version.to_s == $2 }
    base_path = version_in_use.rg_full_gem_path
    file = "#{base_path}/#{$3}"
  else 
    # This is an app-local file, and just needs to be joined to Rails.root
    file = Rails.root + file
  end

  url = "#{PROTOCOL}://#{line}@#{file}"

  "<a href='#{url}'>#{str}</a>".html_safe
end