delorean 1.2.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/delorean.rb +2 -50
- data/lib/flux_capacitor.rb +53 -0
- metadata +52 -29
data/lib/delorean.rb
CHANGED
@@ -1,57 +1,9 @@
|
|
1
1
|
require 'chronic'
|
2
|
+
require 'flux_capacitor'
|
2
3
|
|
3
4
|
module Delorean
|
5
|
+
include FluxCapacitor
|
4
6
|
extend self
|
5
|
-
|
6
|
-
def time_travel_to(time, options={})
|
7
|
-
mock_current_time(time, options)
|
8
|
-
return unless block_given?
|
9
|
-
begin
|
10
|
-
yield
|
11
|
-
ensure
|
12
|
-
restore_previous_time
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
def back_to_the_present
|
17
|
-
reset
|
18
|
-
end
|
19
|
-
alias :back_to_1985 :back_to_the_present
|
20
|
-
|
21
|
-
def jump(seconds)
|
22
|
-
mock_current_time Time.now + seconds
|
23
|
-
return unless block_given?
|
24
|
-
begin
|
25
|
-
yield
|
26
|
-
ensure
|
27
|
-
restore_previous_time
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
def now
|
32
|
-
Time.now_without_delorean - time_travel_offsets.inject(0){ |sum, val| sum + val }
|
33
|
-
end
|
34
|
-
|
35
|
-
private
|
36
|
-
|
37
|
-
def time_travel_offsets
|
38
|
-
@@time_travel_offsets ||= []
|
39
|
-
end
|
40
|
-
|
41
|
-
def reset
|
42
|
-
@@time_travel_offsets = []
|
43
|
-
end
|
44
|
-
|
45
|
-
def mock_current_time(time, options={})
|
46
|
-
time = Chronic.parse(time, options) if time.is_a?(String)
|
47
|
-
time = Time.local(time.year, time.month, time.day) if time.is_a?(Date) && !time.is_a?(DateTime)
|
48
|
-
|
49
|
-
time_travel_offsets.push Time.now - time
|
50
|
-
end
|
51
|
-
|
52
|
-
def restore_previous_time
|
53
|
-
time_travel_offsets.pop
|
54
|
-
end
|
55
7
|
end
|
56
8
|
|
57
9
|
class << Time
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module Delorean
|
2
|
+
module FluxCapacitor
|
3
|
+
def time_travel_to(time, options={})
|
4
|
+
mock_current_time(time, options)
|
5
|
+
return unless block_given?
|
6
|
+
begin
|
7
|
+
yield
|
8
|
+
ensure
|
9
|
+
restore_previous_time
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def back_to_the_present
|
14
|
+
reset
|
15
|
+
end
|
16
|
+
alias :back_to_1985 :back_to_the_present
|
17
|
+
|
18
|
+
def jump(seconds)
|
19
|
+
mock_current_time Time.now + seconds
|
20
|
+
return unless block_given?
|
21
|
+
begin
|
22
|
+
yield
|
23
|
+
ensure
|
24
|
+
restore_previous_time
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def now
|
29
|
+
Time.now_without_delorean - time_travel_offsets.inject(0){ |sum, val| sum + val }
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def time_travel_offsets
|
35
|
+
@@time_travel_offsets ||= []
|
36
|
+
end
|
37
|
+
|
38
|
+
def reset
|
39
|
+
@@time_travel_offsets = []
|
40
|
+
end
|
41
|
+
|
42
|
+
def mock_current_time(time, options={})
|
43
|
+
time = Chronic.parse(time, options) if time.is_a?(String)
|
44
|
+
time = Time.local(time.year, time.month, time.day) if time.is_a?(Date) && !time.is_a?(DateTime)
|
45
|
+
|
46
|
+
time_travel_offsets.push Time.now - time
|
47
|
+
end
|
48
|
+
|
49
|
+
def restore_previous_time
|
50
|
+
time_travel_offsets.pop
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
metadata
CHANGED
@@ -1,60 +1,83 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: delorean
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 15
|
5
5
|
prerelease:
|
6
|
+
segments:
|
7
|
+
- 2
|
8
|
+
- 0
|
9
|
+
- 0
|
10
|
+
version: 2.0.0
|
6
11
|
platform: ruby
|
7
|
-
authors:
|
8
|
-
- Luismi
|
12
|
+
authors:
|
13
|
+
- "Luismi Cavall\xC3\xA9"
|
9
14
|
- Sergio Gil
|
10
15
|
autorequire:
|
11
16
|
bindir: bin
|
12
17
|
cert_chain: []
|
13
|
-
|
14
|
-
|
15
|
-
|
18
|
+
|
19
|
+
date: 2012-07-04 00:00:00 Z
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
16
22
|
name: chronic
|
17
|
-
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
18
25
|
none: false
|
19
|
-
requirements:
|
20
|
-
- -
|
21
|
-
- !ruby/object:Gem::Version
|
22
|
-
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
version: "0"
|
23
33
|
type: :runtime
|
24
|
-
|
25
|
-
version_requirements: *70109337304820
|
34
|
+
version_requirements: *id001
|
26
35
|
description:
|
27
36
|
email: ballsbreaking@bebanjo.com
|
28
37
|
executables: []
|
38
|
+
|
29
39
|
extensions: []
|
30
|
-
|
40
|
+
|
41
|
+
extra_rdoc_files:
|
31
42
|
- README.md
|
32
|
-
files:
|
43
|
+
files:
|
33
44
|
- lib/delorean.rb
|
45
|
+
- lib/flux_capacitor.rb
|
34
46
|
- README.md
|
35
47
|
- MIT-LICENSE
|
36
48
|
homepage: http://github.com/bebanjo/delorean
|
37
49
|
licenses: []
|
50
|
+
|
38
51
|
post_install_message:
|
39
52
|
rdoc_options: []
|
40
|
-
|
53
|
+
|
54
|
+
require_paths:
|
41
55
|
- lib
|
42
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
56
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
43
57
|
none: false
|
44
|
-
requirements:
|
45
|
-
- -
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
|
48
|
-
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
hash: 3
|
62
|
+
segments:
|
63
|
+
- 0
|
64
|
+
version: "0"
|
65
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
49
66
|
none: false
|
50
|
-
requirements:
|
51
|
-
- -
|
52
|
-
- !ruby/object:Gem::Version
|
53
|
-
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
hash: 3
|
71
|
+
segments:
|
72
|
+
- 0
|
73
|
+
version: "0"
|
54
74
|
requirements: []
|
75
|
+
|
55
76
|
rubyforge_project:
|
56
|
-
rubygems_version: 1.8.
|
77
|
+
rubygems_version: 1.8.17
|
57
78
|
signing_key:
|
58
79
|
specification_version: 3
|
59
80
|
summary: Delorean lets you travel in time with Ruby by mocking Time.now
|
60
81
|
test_files: []
|
82
|
+
|
83
|
+
has_rdoc:
|