Class: SiteHealth::Timer

Inherits:
Object
  • Object
show all
Defined in:
lib/site_health/timer.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#finished_atObject (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_atObject (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

.startObject



9
10
11
# File 'lib/site_health/timer.rb', line 9

def self.start
  new.tap(&:start)
end

Instance Method Details

#diffObject



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

#finishObject



29
30
31
32
# File 'lib/site_health/timer.rb', line 29

def finish
  @finished = high_precision_time
  @finished_at = Time.now
end

#measureObject



17
18
19
20
21
22
# File 'lib/site_health/timer.rb', line 17

def measure
  start
  yield
  finish
  self
end

#startObject



24
25
26
27
# File 'lib/site_health/timer.rb', line 24

def start
  @started = high_precision_time
  @started_at = Time.now
end