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                          # Actual
].freeze

Instance Method Summary collapse

Constructor Details

#initialize(time = ::Time) ⇒ Time

Returns a new instance of Time.



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

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

Instance Method Details

#nowObject



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

def now
  time.__send__ unmocked_time_method
end

#unmocked_time_methodObject



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

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