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.
28 29 30 31 32 |
# File 'lib/console/measure.rb', line 28 def initialize(output, subject, **) @output = output @subject = subject @tags = end |
Instance Attribute Details
#tags ⇒ Object (readonly)
Returns the value of attribute tags.
34 35 36 |
# File 'lib/console/measure.rb', line 34 def @tags end |
Instance Method Details
#duration(name, &block) ⇒ Object
Measure the execution of a block of code.
37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/console/measure.rb', line 37 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 |