Class: Vedeu::Logging::Timer Private
- Inherits:
-
Object
- Object
- Vedeu::Logging::Timer
- Defined in:
- lib/vedeu/logging/timer.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Measure the duration. Used for debugging. The configuration option ‘debug’ must be set to true to enable this functionality.
Instance Attribute Summary collapse
- #message ⇒ String readonly protected private
- #started ⇒ Time readonly protected private
Class Method Summary collapse
Instance Method Summary collapse
-
#elapsed ⇒ Float
private
private
Returns the elapsed time in milliseconds with 3 decimal places.
-
#initialize(message = '') ⇒ Vedeu::Logging::Timer
constructor
private
Returns a new instance of Vedeu::Logging::Timer.
-
#measure(&block) ⇒ void|NilClass
private
Write an entry to the log file stating how long a section of code took in milliseconds when debugging is enabled and a block was Useful for debugging performance.
Constructor Details
#initialize(message = '') ⇒ Vedeu::Logging::Timer
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Vedeu::Logging::Timer.
32 33 34 35 |
# File 'lib/vedeu/logging/timer.rb', line 32 def initialize( = '') @message = @started = Vedeu.clock_time end |
Instance Attribute Details
#message ⇒ String (readonly, protected)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
70 71 72 |
# File 'lib/vedeu/logging/timer.rb', line 70 def @message end |
#started ⇒ Time (readonly, protected)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
66 67 68 |
# File 'lib/vedeu/logging/timer.rb', line 66 def started @started end |
Class Method Details
.timer(message = '', &block) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
22 23 24 |
# File 'lib/vedeu/logging/timer.rb', line 22 def timer( = '', &block) new().measure(&block) end |
Instance Method Details
#elapsed ⇒ Float (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the elapsed time in milliseconds with 3 decimal places.
78 79 80 |
# File 'lib/vedeu/logging/timer.rb', line 78 def elapsed ((Vedeu.clock_time - started) * 1000).round(3) end |
#measure(&block) ⇒ void|NilClass
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Write an entry to the log file stating how long a section of code took in milliseconds when debugging is enabled and a block was Useful for debugging performance.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/vedeu/logging/timer.rb', line 45 def measure(&block) raise Vedeu::Error::RequiresBlock unless block_given? if Vedeu.config.debug? work = yield Vedeu.log(type: :timer, message: "#{} took #{elapsed}ms.") work else yield end end |