Class: ProgressBar::Time

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby-progressbar/time.rb

Constant Summary collapse

TIME_MOCKING_LIBRARY_METHODS =
[
  :__simple_stub__now,     # ActiveSupport
  :now_without_mock_time,  # Timecop
  :now_without_delorean,   # Delorean
  :now                     # Unmocked
].freeze

Instance Method Summary collapse

Constructor Details

#initialize(time = ::Time) ⇒ Time

Returns a new instance of Time.



11
12
13
# File 'lib/ruby-progressbar/time.rb', line 11

def initialize(time = ::Time)
  self.time = time
end

Instance Method Details

#nowObject



15
16
17
# File 'lib/ruby-progressbar/time.rb', line 15

def now
  time.__send__(unmocked_time_method)
end

#unmocked_time_methodObject



19
20
21
22
23
# File 'lib/ruby-progressbar/time.rb', line 19

def unmocked_time_method
  @unmocked_time_method ||= TIME_MOCKING_LIBRARY_METHODS.find do |method|
    time.respond_to? method
  end
end