timecop-redis 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +4 -0
- data/lib/timecop/redis.rb +8 -5
- data/lib/timecop/redis/timecop_integration.rb +21 -0
- data/lib/timecop/redis/traveler.rb +4 -3
- data/lib/timecop/redis/version.rb +2 -2
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1c99ecbe597f9e53954ca9f5f9307217316791d02c573960177fea40f5e09ec9
|
4
|
+
data.tar.gz: 7e3fd8c3ae105a82ba1a5c4e41f8842cb952c92254809622deee1810ca58e5f1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1f505f22e20ccc91403810d3c4636b44ec75eed83108fd8fa063a8ff304dfa4fdddefc8fe995a2882c14437d7671bcecf908e1521e64c3d389b47c8695d43ed2
|
7
|
+
data.tar.gz: e97c5e6ea015981c9b8f30f3d4a26cd013050b3839aa3be40baff6a4e931333afc8cdbafbd3c45bf00c1fdb72ab1697ad11f780bab0a5bda8135695d1d1b3846
|
data/.rubocop.yml
CHANGED
data/lib/timecop/redis.rb
CHANGED
@@ -1,10 +1,13 @@
|
|
1
|
+
require_relative 'redis/timecop_integration'
|
1
2
|
require_relative 'redis/traveler'
|
2
3
|
require 'redis'
|
3
|
-
require 'timecop'
|
4
4
|
|
5
5
|
class Timecop
|
6
6
|
module Redis
|
7
7
|
class << self
|
8
|
+
attr_accessor :integrate_into_timecop_travel
|
9
|
+
alias integrate_into_timecop_travel? integrate_into_timecop_travel
|
10
|
+
|
8
11
|
def redis
|
9
12
|
@redis || ::Redis.current
|
10
13
|
end
|
@@ -14,15 +17,15 @@ class Timecop
|
|
14
17
|
@traveler = nil
|
15
18
|
end
|
16
19
|
|
17
|
-
def travel(new_time)
|
18
|
-
traveler.travel(new_time)
|
20
|
+
def travel(new_time, &block)
|
21
|
+
traveler.travel(from: Time.now, to: new_time, &block)
|
19
22
|
end
|
20
23
|
|
21
|
-
private
|
22
|
-
|
23
24
|
def traveler
|
24
25
|
@traveler ||= Traveler.new(redis)
|
25
26
|
end
|
26
27
|
end
|
28
|
+
|
29
|
+
self.integrate_into_timecop_travel = false
|
27
30
|
end
|
28
31
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'timecop'
|
2
|
+
|
3
|
+
# We directly patch Timecop class instead of mixin module
|
4
|
+
# since Singleton classes cannot be extended.
|
5
|
+
# https://github.com/ruby/ruby/blob/v2_5_0/lib/singleton.rb#L150-L151
|
6
|
+
class Timecop
|
7
|
+
alias travel_without_redis travel
|
8
|
+
|
9
|
+
def travel_with_redis(*args, &block)
|
10
|
+
if Timecop::Redis.integrate_into_timecop_travel?
|
11
|
+
old_time = Time.now
|
12
|
+
travel_without_redis(*args, &block)
|
13
|
+
new_time = Time.now
|
14
|
+
Timecop::Redis.traveler.travel(from: old_time, to: new_time, &block)
|
15
|
+
else
|
16
|
+
travel_without_redis(*args, &block)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
alias travel travel_with_redis
|
21
|
+
end
|
@@ -7,9 +7,10 @@ class Timecop
|
|
7
7
|
@redis = redis
|
8
8
|
end
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
def travel(from:, to:)
|
11
|
+
raise ArgumentError, 'Auto-rewind block is not yet supported' if block_given?
|
12
|
+
|
13
|
+
advanced_milliseconds = ((to - from) * 1000).to_i
|
13
14
|
|
14
15
|
expirable_keys.each do |key, old_remaining_milliseconds|
|
15
16
|
new_remaining_milliseconds = old_remaining_milliseconds - advanced_milliseconds
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: timecop-redis
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yuji Nakayama
|
@@ -70,6 +70,7 @@ files:
|
|
70
70
|
- bin/console
|
71
71
|
- bin/setup
|
72
72
|
- lib/timecop/redis.rb
|
73
|
+
- lib/timecop/redis/timecop_integration.rb
|
73
74
|
- lib/timecop/redis/traveler.rb
|
74
75
|
- lib/timecop/redis/version.rb
|
75
76
|
- timecop-redis.gemspec
|