Class: Clock::Substitute

Inherits:
Object
  • Object
show all
Includes:
Clock
Defined in:
lib/clock/substitute.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Clock

#canonize, #elapsed_milliseconds, included, local, #now, #parse, #timestamp, utc

Methods included from Now

#now

Methods included from Canonize

#canonize

Methods included from ISO8601

#precision

Methods included from Parse

#parse

Methods included from ElapsedMilliseconds

#elapsed_milliseconds

Methods included from Timestamp

#timestamp

Instance Attribute Details

#system_timeObject



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

def system_time
  @system_time ||= self.class.null_time
end

Class Method Details

.null_timeObject



25
26
27
28
29
30
# File 'lib/clock/substitute.rb', line 25

def self.null_time
  Mimic.(Object) do
    def method_missing(*)
    end
  end
end

Instance Method Details

#iso8601(time = nil, precision: nil) ⇒ Object



18
19
20
21
22
23
# File 'lib/clock/substitute.rb', line 18

def iso8601(time=nil, precision: nil)
  if system_time.is_a? OpenStruct
    return super(time, precision: precision)
  end
  nil
end

#now=(val) ⇒ Object



11
12
13
14
15
16
# File 'lib/clock/substitute.rb', line 11

def now=(val)
  system_time = OpenStruct.new
  system_time.now = val
  self.system_time = system_time
  system_time
end