module QuantumLeap::Accelerator
Internal: The main module for methods that manipulate time, and provide interfaces to the custom time.
All methods are module methods and should be called on the QuantumLeap::Accelerator
module.
Examples
QuantumLeap::Accelerator.mock_current_time(Time.new(1956, 9, 13)) # => [1788820900.589824] QuantumLeap::Accelerator.time_travel_offsets # => [1788820900.589824] QuantumLeap::Accelerator.now # => 1956-09-13 00:00:01 -0700 QuantumLeap::Accelerator.date # => #<Date: 1956-09-13 ((2435730j,0s,0n),+0s,2299161j)> QuantumLeap::Accelerator.reset # => []
Public Instance Methods
Internal: Add to the stack of time offsets the difference between the actual current time, and the desired new time.
new_time - The past or future Time
to leap to.
Examples
QuantumLeap::Accelerator.mock_current_time(Time.new(1956, 9, 13)) # => [1788820900.589824]
Returns the stack of time offsets, an Array of Floats.
# File lib/quantum_leap/accelerator.rb, line 58 def mock_current_time(new_time) time_travel_offsets.push(Time.now - new_time) end
Internal: Provide the mocked time by applying all offsets to the actual current time.
Examples
QuantumLeap::Accelerator.now # => 1956-09-13 00:00:01 -0700
Returns the mocked current Time
.
# File lib/quantum_leap/accelerator.rb, line 71 def now Time.really_now - time_travel_offsets.inject(0, :+) end
Internal: Empties the stack of time offsets, effectively resetting the current time to the actual time.
Returns an empty Array.
# File lib/quantum_leap/accelerator.rb, line 43 def reset @time_travel_offsets = [] end
Internal: Return or initialize the stack of time offsets as Floats.
Examples
QuantumLeap::Accelerator.time_travel_offsets # => [1788820900.589824]
Returns an empty Array or an Array of Floats.
# File lib/quantum_leap/accelerator.rb, line 35 def time_travel_offsets @time_travel_offsets ||= [] end