Module: Duvet

Defined in:
lib/duvet.rb,
lib/duvet/cov.rb,
lib/duvet/covs.rb,
lib/duvet/version.rb

Defined Under Namespace

Classes: Cov, Covs

Constant Summary collapse

DEFAULTS =
{:dir => 'cov', :style => 'rcov'}
TEMPLATE_PATH =
Pathname.new(__FILE__).dirname + '..' + 'templates'
TEMPLATE_HASH =
{
  'time' => Time.now,
  'version' => VERSION,
  'name' => 'duvet'
}
VERSION =
'0.3.3'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#optsObject

Returns the value of attribute opts.



19
20
21
# File 'lib/duvet.rb', line 19

def opts
  @opts
end

Class Method Details

.at_exitObject

TODO:

Allow user to override block used

Proc to call when exiting



64
65
66
# File 'lib/duvet.rb', line 64

def self.at_exit
  Proc.new { self.write }
end

.resultObject

Get result



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/duvet.rb', line 40

def self.result
  cov = Coverage.result if running?
  if @opts[:filter]
    filtered = {}
    @opts[:filter] = /#{@opts[:filter]}/ unless @opts[:filter].is_a?(Regexp)
    cov.each do |k, v|
      if @opts[:filter] =~ k
        filtered[k] = v
      end
    end
    cov = filtered
  end
  @result ||= Duvet::Covs.new(cov)
ensure
  @running = false
end

.running?Boolean

Returns whether coverage is running.

Returns:

  • (Boolean)

    whether coverage is running



69
70
71
# File 'lib/duvet.rb', line 69

def self.running?
  @running
end

.start(opts = {}) ⇒ Object

Start tracking



32
33
34
35
36
37
# File 'lib/duvet.rb', line 32

def self.start(opts={})
  @opts = DEFAULTS.merge(opts)
  
  Coverage.start
  @running = true
end

.writeObject

Write results



58
59
60
# File 'lib/duvet.rb', line 58

def self.write
  self.result.write(Pathname.new(@opts[:dir])) if running?
end