Class: DeepTest::Metrics::Gatherer

Inherits:
Object
  • Object
show all
Defined in:
lib/deep_test/metrics/gatherer.rb

Defined Under Namespace

Classes: Section

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Gatherer

Returns a new instance of Gatherer.



21
22
23
24
# File 'lib/deep_test/metrics/gatherer.rb', line 21

def initialize(options)
  @options = options
  @sections = []
end

Class Method Details

.enabled?Boolean

Returns:

  • (Boolean)


12
13
14
15
# File 'lib/deep_test/metrics/gatherer.rb', line 12

def self.enabled?
  return false unless $metrics_gatherer
  $metrics_gatherer.enabled?
end

.section(title, &block) ⇒ Object



17
18
19
# File 'lib/deep_test/metrics/gatherer.rb', line 17

def self.section(title, &block)
  $metrics_gatherer.section(title, &block)
end

.setup(options) ⇒ Object



4
5
6
7
8
9
10
# File 'lib/deep_test/metrics/gatherer.rb', line 4

def self.setup(options)
  $metrics_gatherer = new(options)

  at_exit do
    $metrics_gatherer.write_file
  end
end

Instance Method Details

#enabled?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/deep_test/metrics/gatherer.rb', line 26

def enabled?
  !@options.metrics_file.nil?
end

#renderObject



34
35
36
# File 'lib/deep_test/metrics/gatherer.rb', line 34

def render
  @sections.map {|s| s.render}.join("\n")
end

#section(title, &block) ⇒ Object



30
31
32
# File 'lib/deep_test/metrics/gatherer.rb', line 30

def section(title, &block)
  @sections << Section.new(title, &block) if enabled?
end

#write_fileObject



38
39
40
41
42
43
# File 'lib/deep_test/metrics/gatherer.rb', line 38

def write_file
  return unless enabled?
  File.open(@options.metrics_file, "w") do |io|
    io << render
  end
end