timecop-redis 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 126f408065b28e19b4f9b378f1fbe208eafadd1ea3ae632bf552cd493229e6d7
4
- data.tar.gz: 3977ba609d9eb8fea74c362a82effd18b50e76d24d15c51f7dd3241a76cd31cc
3
+ metadata.gz: 1c99ecbe597f9e53954ca9f5f9307217316791d02c573960177fea40f5e09ec9
4
+ data.tar.gz: 7e3fd8c3ae105a82ba1a5c4e41f8842cb952c92254809622deee1810ca58e5f1
5
5
  SHA512:
6
- metadata.gz: c686711fdd85df87bf1ff562a127f7dba3e587fedad8f44407c3f20ec3bef973afe75f85d2c8a66c1b7ee59f301e8be1a63840574764ce4bf6ae1abe5b5ac805
7
- data.tar.gz: f75e023104d368ac9f6ba3847f89543cb534ae5f4e943dbd0df20955375b55d2e9da531c37919e0ac597f1974ba101c2f90a6d2cb488a88412227531aa9b014d
6
+ metadata.gz: 1f505f22e20ccc91403810d3c4636b44ec75eed83108fd8fa063a8ff304dfa4fdddefc8fe995a2882c14437d7671bcecf908e1521e64c3d389b47c8695d43ed2
7
+ data.tar.gz: e97c5e6ea015981c9b8f30f3d4a26cd013050b3839aa3be40baff6a4e931333afc8cdbafbd3c45bf00c1fdb72ab1697ad11f780bab0a5bda8135695d1d1b3846
@@ -1,6 +1,10 @@
1
1
  Layout/MultilineMethodCallIndentation:
2
2
  Enabled: false
3
3
 
4
+ Lint/AmbiguousBlockAssociation:
5
+ Exclude:
6
+ - spec/**/*
7
+
4
8
  Metrics/BlockLength:
5
9
  Exclude:
6
10
  - spec/**/*
@@ -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
- # TODO: Support auto-rewind block
11
- def travel(new_time)
12
- advanced_milliseconds = ((new_time - Time.now) * 1000).to_i
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
@@ -3,8 +3,8 @@ class Timecop
3
3
  # http://semver.org/
4
4
  module Version
5
5
  MAJOR = 0
6
- MINOR = 1
7
- PATCH = 1
6
+ MINOR = 2
7
+ PATCH = 0
8
8
 
9
9
  def self.to_s
10
10
  [MAJOR, MINOR, PATCH].join('.')
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.1.1
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