Class: DeepTest::Metrics::Gatherer
- Inherits:
-
Object
- Object
- DeepTest::Metrics::Gatherer
- Defined in:
- lib/deep_test/metrics/gatherer.rb
Defined Under Namespace
Classes: Section
Class Method Summary collapse
Instance Method Summary collapse
- #enabled? ⇒ Boolean
-
#initialize(options) ⇒ Gatherer
constructor
A new instance of Gatherer.
- #render ⇒ Object
- #section(title, &block) ⇒ Object
- #write_file ⇒ Object
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 = @sections = [] end |
Class Method Details
.enabled? ⇒ 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() $metrics_gatherer = new() at_exit do $metrics_gatherer.write_file end end |
Instance Method Details
#enabled? ⇒ Boolean
26 27 28 |
# File 'lib/deep_test/metrics/gatherer.rb', line 26 def enabled? !@options.metrics_file.nil? end |
#render ⇒ Object
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_file ⇒ Object
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 |