Class: OpenHAB::RSpec::Mocks::Timer
- Inherits:
-
Core::Timer
- Object
- Core::Timer
- OpenHAB::RSpec::Mocks::Timer
- Defined in:
- lib/openhab/rspec/mocks/timer.rb
Instance Attribute Summary collapse
-
#block ⇒ Object
readonly
Returns the value of attribute block.
-
#execution_time ⇒ Object
readonly
Returns the value of attribute execution_time.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
Class Method Summary collapse
-
.mock_timers(mock_timers) { ... } ⇒ Object
Temporarily mock or unmock timers.
-
.mock_timers? ⇒ true, false
If timers are currently mocked.
Instance Method Summary collapse
- #active? ⇒ Boolean
- #cancel ⇒ Object
- #cancel! ⇒ Object
- #cancelled? ⇒ Boolean
- #execute ⇒ Object
-
#initialize(time, id:, thread_locals:, block:) ⇒ Timer
constructor
rubocop:disable Lint/MissingSuper.
- #reschedule!(time = nil) ⇒ Object
- #running? ⇒ Boolean
- #terminated? ⇒ Boolean
Methods inherited from Core::Timer
Constructor Details
#initialize(time, id:, thread_locals:, block:) ⇒ Timer
rubocop:disable Lint/MissingSuper
113 114 115 116 117 118 119 |
# File 'lib/openhab/rspec/mocks/timer.rb', line 113 def initialize(time, id:, thread_locals:, block:) # rubocop:disable Lint/MissingSuper @time = time @id = id @block = block @thread_locals = thread_locals reschedule!(time) end |
Instance Attribute Details
#block ⇒ Object (readonly)
Returns the value of attribute block.
111 112 113 |
# File 'lib/openhab/rspec/mocks/timer.rb', line 111 def block @block end |
#execution_time ⇒ Object (readonly)
Returns the value of attribute execution_time.
111 112 113 |
# File 'lib/openhab/rspec/mocks/timer.rb', line 111 def execution_time @execution_time end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
111 112 113 |
# File 'lib/openhab/rspec/mocks/timer.rb', line 111 def id @id end |
Class Method Details
.mock_timers(mock_timers) { ... } ⇒ Object
Temporarily mock or unmock timers
88 89 90 91 92 93 94 |
# File 'lib/openhab/rspec/mocks/timer.rb', line 88 def mock_timers(mock_timers) old_mock_timers = @mock_timers @mock_timers = mock_timers yield ensure @mock_timers = old_mock_timers end |
.mock_timers? ⇒ true, false
If timers are currently mocked
78 79 80 |
# File 'lib/openhab/rspec/mocks/timer.rb', line 78 def mock_timers? @mock_timers end |
Instance Method Details
#active? ⇒ Boolean
164 165 166 |
# File 'lib/openhab/rspec/mocks/timer.rb', line 164 def active? !terminated? end |
#cancel ⇒ Object
139 140 141 142 143 144 145 |
# File 'lib/openhab/rspec/mocks/timer.rb', line 139 def cancel return false if terminated? || cancelled? DSL::TimerManager.instance.delete(self) cancel! true end |
#cancel! ⇒ Object
147 148 149 150 |
# File 'lib/openhab/rspec/mocks/timer.rb', line 147 def cancel! @execution_time = nil true end |
#cancelled? ⇒ Boolean
152 153 154 |
# File 'lib/openhab/rspec/mocks/timer.rb', line 152 def cancelled? @execution_time.nil? end |
#execute ⇒ Object
131 132 133 134 135 136 137 |
# File 'lib/openhab/rspec/mocks/timer.rb', line 131 def execute raise "Timer already cancelled" if cancelled? raise "Timer already executed" if terminated? @executed = true super end |
#reschedule!(time = nil) ⇒ Object
121 122 123 124 125 126 127 128 129 |
# File 'lib/openhab/rspec/mocks/timer.rb', line 121 def reschedule!(time = nil) Thread.current[:openhab_rescheduled_timer] = true if Thread.current[:openhab_rescheduled_timer] == self @execution_time = new_execution_time(time || @time) @executed = false DSL::TimerManager.instance.add(self) self end |
#running? ⇒ Boolean
160 161 162 |
# File 'lib/openhab/rspec/mocks/timer.rb', line 160 def running? false end |
#terminated? ⇒ Boolean
156 157 158 |
# File 'lib/openhab/rspec/mocks/timer.rb', line 156 def terminated? @executed || cancelled? end |