Class: OpenHAB::DSL::Timer
Defined Under Namespace
Modules: MockedZonedDateTime, TimeCopStackItem
Instance Attribute Summary collapse
Instance Method Summary
collapse
#now
Constructor Details
#initialize(duration:, thread_locals: {}, &block) ⇒ Timer
rubocop:disable Lint/UnusedMethodArgument
31
32
33
34
|
# File 'lib/rspec/openhab/dsl/timers/timer.rb', line 31
def initialize(duration:, thread_locals: {}, &block) @block = block
reschedule(duration)
end
|
Instance Attribute Details
#execution_time ⇒ Object
Returns the value of attribute execution_time.
29
30
31
|
# File 'lib/rspec/openhab/dsl/timers/timer.rb', line 29
def execution_time
@execution_time
end
|
Instance Method Details
#active? ⇒ Boolean
72
73
74
|
# File 'lib/rspec/openhab/dsl/timers/timer.rb', line 72
def active?
!terminated?
end
|
#cancel ⇒ Object
53
54
55
56
57
58
|
# File 'lib/rspec/openhab/dsl/timers/timer.rb', line 53
def cancel
Timers.timer_manager.delete(self)
@executed = false
@cancelled = true
true
end
|
#cancelled? ⇒ Boolean
60
61
62
|
# File 'lib/rspec/openhab/dsl/timers/timer.rb', line 60
def cancelled?
@cancelled
end
|
#execute ⇒ Object
44
45
46
47
48
49
50
51
|
# File 'lib/rspec/openhab/dsl/timers/timer.rb', line 44
def execute
raise "Timer already cancelled" if cancelled?
raise "Timer already executed" if terminated?
@block.call(self)
Timers.timer_manager.delete(self)
@executed = true
end
|
#reschedule(duration = nil) ⇒ Object
36
37
38
39
40
41
42
|
# File 'lib/rspec/openhab/dsl/timers/timer.rb', line 36
def reschedule(duration = nil)
@duration = duration || @duration
@execution_time = ZonedDateTime.now.plus(@duration)
@executed = @cancelled = false
Timers.timer_manager.add(self)
end
|
#running? ⇒ Boolean
68
69
70
|
# File 'lib/rspec/openhab/dsl/timers/timer.rb', line 68
def running?
active? && @execution_time > ZonedDateTime.now
end
|
#terminated? ⇒ Boolean
64
65
66
|
# File 'lib/rspec/openhab/dsl/timers/timer.rb', line 64
def terminated?
@executed || @cancelled
end
|