Module: TimeFreeze

Defined in:
lib/time_freeze.rb

Constant Summary collapse

@@frozen_time =
nil

Class Method Summary collapse

Class Method Details

.freeze!(frozen_time = Time.now) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/time_freeze.rb', line 15

def self.freeze!(frozen_time=Time.now)
  raise ArgumentError, "we can only freeze to a Time" unless frozen_time.is_a?(Time)
  TimeFreeze.frozen_time, time_before = frozen_time, TimeFreeze.frozen_time
  yield
ensure
  # no matter what happens
  # we need to reset this
  TimeFreeze.frozen_time = time_before
end

.frozen_timeObject



7
8
9
# File 'lib/time_freeze.rb', line 7

def self.frozen_time
  @@frozen_time
end

.frozen_time=(value) ⇒ Object



11
12
13
# File 'lib/time_freeze.rb', line 11

def self.frozen_time=(value)
  @@frozen_time = value
end

.unfreeze!Object



25
26
27
# File 'lib/time_freeze.rb', line 25

def self.unfreeze!
  self.frozen_time=nil
end