Class: Insurance::RailsAnalyzer

Inherits:
Analyzer
  • Object
show all
Defined in:
lib/insurance/analyzer.rb

Constant Summary collapse

@@dir_regexp =
Regexp.new("^#{Dir.pwd}/(?:lib|app/(?:models|controllers))/")
@@_path_cache =
{}

Class Method Summary collapse

Methods inherited from Analyzer

line_trace_func

Class Method Details

.filter(file) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/insurance/analyzer.rb', line 40

def self.filter(file)
  begin
    full_path =  @@_path_cache[file] || (@@_path_cache[file] = File.expand_path(file))
    if @@dir_regexp =~ full_path
      pwd = Dir.pwd
      return full_path[(full_path.index(pwd)+pwd.length+1)..-1]
    else
      return false
    end
  rescue
    return false
  end
end

.run(files) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/insurance/analyzer.rb', line 54

def self.run(files)
  # The rails analyzer does not need to set the trace func, because that is
  # done in the perversion of Test::Unit::TestCase.
  
  # Since we flip tracing on only right before a test is executed, to avoid
  # tracing the entire framework at all times (very slow), we need to pre-load
  # all of the application's models and controllers so that we can trace things
  # at the class level.  This is just easier to do than to try and figure out
  # what should really be marked as hit in the output stage.
  
  pipe = IO.popen('-', 'w+')
  if pipe
    Insurance::FILELIST.merge!(YAML::load(pipe.read))
    files.each { |f| load f }
  else
    at_exit {
      Insurance.set_trace_func nil
      puts Insurance::FILELIST.to_yaml
      exit!
    }
    
    require 'config/environment'
    Insurance.set_trace_func self.method(:line_trace_func).to_proc
    require 'application'
    (Dir['app/models/**/*.rb'] + Dir['app/controllers/**/*.rb']).each { |f| load f }
 end
end