Class: SiteHealth::Timer
- Inherits:
-
Object
- Object
- SiteHealth::Timer
- Defined in:
- lib/site_health/timer.rb
Instance Attribute Summary collapse
-
#finished_at ⇒ Object
readonly
Returns the value of attribute finished_at.
-
#started_at ⇒ Object
readonly
Returns the value of attribute started_at.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#finished_at ⇒ Object (readonly)
Returns the value of attribute finished_at.
7 8 9 |
# File 'lib/site_health/timer.rb', line 7 def finished_at @finished_at end |
#started_at ⇒ Object (readonly)
Returns the value of attribute started_at.
7 8 9 |
# File 'lib/site_health/timer.rb', line 7 def started_at @started_at end |
Class Method Details
.measure(&block) ⇒ Object
13 14 15 |
# File 'lib/site_health/timer.rb', line 13 def self.measure(&block) new.tap { |timer| timer.measure(&block) } end |
.start ⇒ Object
9 10 11 |
# File 'lib/site_health/timer.rb', line 9 def self.start new.tap(&:start) end |
Instance Method Details
#diff ⇒ Object
34 35 36 37 38 39 |
# File 'lib/site_health/timer.rb', line 34 def diff fail(StandardError, 'timer must be started') unless @started finish = @finished || high_precision_time finish - @started end |
#finish ⇒ Object
29 30 31 32 |
# File 'lib/site_health/timer.rb', line 29 def finish @finished = high_precision_time @finished_at = Time.now end |
#measure ⇒ Object
17 18 19 20 21 22 |
# File 'lib/site_health/timer.rb', line 17 def measure start yield finish self end |
#start ⇒ Object
24 25 26 27 |
# File 'lib/site_health/timer.rb', line 24 def start @started = high_precision_time @started_at = Time.now end |