Module: CoverMe

Defined in:
lib/cover_me.rb,
lib/cover_me/config.rb,
lib/cover_me/results.rb,
lib/generators/cover_me/install/install_generator.rb

Defined Under Namespace

Modules: Results Classes: DirectoryReport, EmmaFormatter, Formatter, GlobalReport, HtmlFormatter, Index, InstallGenerator, Processor, Report

Class Method Summary collapse

Class Method Details

.complete!Object



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/cover_me.rb', line 12

def complete!
  data_file = CoverMe.config.results.store

  if File.exists?(data_file)
    data = CoverMe::Results.read_results(data_file)

    CoverMe::Processor.new(data).process!
    CoverMe.config.at_exit.call
    
    File.delete(data_file)
  end
end

.config {|configatron.cover_me| ... } ⇒ Object

Yields up a configuration object when given a block. Without a block it just returns the configuration object. Uses Configatron under the covers.

Example:

CoverMe.config do |c|
  c.foo = :bar
end

CoverMe.config.foo # => :bar

Yields:

  • (configatron.cover_me)


15
16
17
18
# File 'lib/cover_me/config.rb', line 15

def config(&block)
  yield configatron.cover_me if block_given?
  configatron.cover_me
end

.set_defaultsObject

:nodoc:



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/cover_me/config.rb', line 20

def set_defaults # :nodoc:
  CoverMe.config do |c|
    c.project.set_default(:root,
      Configatron::Delayed.new{defined?(Rails) ? Rails.root.to_s : Dir.pwd})
    c.results.set_default(:store, Configatron::Delayed.new {File.join(CoverMe.config.project.root, 'coverage.data')})
    c.set_default(:file_pattern, Configatron::Delayed.new do
      [
        /(#{CoverMe.config.project.root}\/app\/.+\.rb)/i,
        /(#{CoverMe.config.project.root}\/lib\/.+\.rb)/i
      ]
    end)
    c.set_default(:exclude_file_patterns, Configatron::Delayed.new do
      []
    end)
    
    c.proximity.set_default(:near, 90)
    c.proximity.set_default(:hit, 100)
    
    c.set_default(:formatter, Configatron::Delayed.new {CoverMe::HtmlFormatter})
    c.set_default(:at_exit, Proc.new {
      if CoverMe.config.formatter == CoverMe::HtmlFormatter
        index = File.join(CoverMe.config.html_formatter.output_path, 'index.html')
        if File.exists?(index)
          cmd = case RUBY_PLATFORM
                when /darwin/
                  'open'
                when /linux/
                  '/etc/alternatives/x-www-browser'
                when /mswin|mingw/
                  'start'
                when /cygwin/
                  'cygstart'
                else
                  'firefox'
                end
          `#{cmd} #{index}`
        end
      end
    })
    c.html_formatter.set_default(:output_path, Configatron::Delayed.new {File.join(CoverMe.config.project.root, 'coverage')})
    c.html_formatter.set_default(:finalizer_files, {'report.css' => 'report.css', 'index.css' => 'index.css', 
                                                    'jquery.js' => 'jquery.js', 'jquery.tablesorter.js' => 'jquery.tablesorter.js'})
    c.emma_formatter.set_default(:output_path, Configatron::Delayed.new {File.join(CoverMe.config.project.root, 'coverage')})
  end
end