Class: Console::Measure
- Inherits:
-
Object
- Object
- Console::Measure
- Defined in:
- lib/console/measure.rb
Instance Attribute Summary collapse
-
#tags ⇒ Object
readonly
Returns the value of attribute tags.
Instance Method Summary collapse
-
#duration(name, &block) ⇒ Object
Measure the execution of a block of code.
-
#initialize(output, subject, **tags) ⇒ Measure
constructor
A new instance of Measure.
Constructor Details
#initialize(output, subject, **tags) ⇒ Measure
Returns a new instance of Measure.
26 27 28 29 30 |
# File 'lib/console/measure.rb', line 26 def initialize(output, subject, **) @output = output @subject = subject @tags = end |
Instance Attribute Details
#tags ⇒ Object (readonly)
Returns the value of attribute tags.
32 33 34 |
# File 'lib/console/measure.rb', line 32 def @tags end |
Instance Method Details
#duration(name, &block) ⇒ Object
Measure the execution of a block of code.
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/console/measure.rb', line 35 def duration(name, &block) @output.info(@subject) {Event::Enter.new(name)} start_time = Clock.now result = yield(self) duration = Clock.now - start_time @output.info(@subject) {Event::Exit.new(name, duration, **@tags)} return result end |