File: time.rb

package info (click to toggle)
ruby-rack-oauth2 2.2.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 560 kB
  • sloc: ruby: 4,013; makefile: 4
file content (21 lines) | stat: -rw-r--r-- 326 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
class Time
  class << self
    module NowWithFixedTime
      def now
        if @fixed_time
          @fixed_time.dup
        else
          super
        end
      end
    end
    prepend NowWithFixedTime

    def fix(time = Time.now)
      @fixed_time = time
      yield
    ensure
      @fixed_time = nil
    end
  end
end