Class: MetricFu::Heckle::Generator

Inherits:
Base::Generator show all
Defined in:
lib/metric_fu/heckle.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base::Generator

#generate_html, #generate_report, generate_report, #initialize, metric_dir, #save_html, #template_file, #template_name

Methods included from TemplateHelpers

#cycle, #inline_css, #link_to_filename

Constructor Details

This class inherits a constructor from MetricFu::Base::Generator

Class Method Details

.template_nameObject


67
68
69
# File 'lib/metric_fu/heckle.rb', line 67

def self.template_name
  "heckle"
end

Instance Method Details

#analyzeObject


12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/metric_fu/heckle.rb', line 12

def analyze
  files_to_heckle = MetricFu.heckle[:dirs_to_heckle].map{|dir| Dir[File.join(dir, "**/*.rb")] }
  class_names = files_to_heckle.flatten.collect do |f|
    buffer = open(f).readlines.join("\n")
    outline = buffer.scan(/class\s+([\w|:]*)+?/)
    klass = path_to_classname(f).split('::').last
  end      
  class_names.flatten!
  output = {}
  ObjectSpace.each_object(Class) do |klass|
    class_names.each do |name|
      if klass.name =~ /::#{name}$/
        output[name] = `heckle #{name} -t spec/**/#{underscore(name)}_spec.rb`
      end
    end
  end

  @pages = []
  output.each_pair do |name, content|
    page = Page.new(content)
    if page
      page.filename = name
      @pages << page
    end
  end
  generate_pages
end

#generate_page(page) ⇒ Object


49
50
51
# File 'lib/metric_fu/heckle.rb', line 49

def generate_page(page)
  save_html(page.to_html, page.path)
end

#generate_pagesObject


40
41
42
43
44
45
46
47
# File 'lib/metric_fu/heckle.rb', line 40

def generate_pages
  @pages.each do |page|
    #unless MetricFu::MD5Tracker.file_already_counted?(page.filename)
      generate_page(page)
    #end
  end      
  save_html(ERB.new(File.read(template_file)).result(binding))
end

#path_to_classname(s) ⇒ Object


53
54
55
56
57
# File 'lib/metric_fu/heckle.rb', line 53

def path_to_classname(s)
  f = s.sub(/^lib/, '').sub(/\.rb$/, '').split('/')
  f = f.map { |path| path.split(/_/).map { |seg| seg.capitalize }.join }
  f.join('::')
end

#underscore(camel_cased_word) ⇒ Object


59
60
61
62
63
64
65
# File 'lib/metric_fu/heckle.rb', line 59

def underscore(camel_cased_word)
  camel_cased_word.to_s.gsub(/::/, '/').
  gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
  gsub(/([a-z\d])([A-Z])/,'\1_\2').
  gsub("-", "_").
  downcase
end