module Delorean::FluxCapacitor
Public Instance Methods
back_to_the_present()
click to toggle source
# File lib/flux_capacitor.rb, line 13 def back_to_the_present reset end
Also aliased as: back_to_1985
jump(seconds) { || ... }
click to toggle source
# File lib/flux_capacitor.rb, line 18 def jump(seconds) mock_current_time Time.now + seconds return unless block_given? begin yield ensure restore_previous_time end end
now()
click to toggle source
# File lib/flux_capacitor.rb, line 28 def now Time.now_without_delorean - time_travel_offsets.inject(0){ |sum, val| sum + val } end
time_travel_to(time, options={}) { || ... }
click to toggle source
# File lib/flux_capacitor.rb, line 3 def time_travel_to(time, options={}) mock_current_time(time, options) return unless block_given? begin yield ensure restore_previous_time end end
Private Instance Methods
mock_current_time(time, options={})
click to toggle source
# File lib/flux_capacitor.rb, line 42 def mock_current_time(time, options={}) time = Chronic.parse(time, options) if time.is_a?(String) time = Time.local(time.year, time.month, time.day) if time.is_a?(Date) && !time.is_a?(DateTime) time_travel_offsets.push Time.now - time end
reset()
click to toggle source
# File lib/flux_capacitor.rb, line 38 def reset @@time_travel_offsets = [] end
restore_previous_time()
click to toggle source
# File lib/flux_capacitor.rb, line 49 def restore_previous_time time_travel_offsets.pop end
time_travel_offsets()
click to toggle source
# File lib/flux_capacitor.rb, line 34 def time_travel_offsets @@time_travel_offsets ||= [] end