timeloop 1.0.0 → 1.0.3
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 +8 -8
- data/.travis.yml +4 -5
- data/README.md +3 -3
- data/lib/timeloop.rb +59 -4
- data/lib/timeloop/version.rb +1 -1
- data/spec/spec_helper.rb +3 -0
- data/timeloop.gemspec +1 -0
- metadata +16 -3
- data/lib/timeloop/every.rb +0 -58
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MTMzN2I2ZmE3MGY1MjMyMzY5ZWQxOTNkNDVhMDljYjc0OWQ0MTk5NQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ODYxODZmNWFlOTM5Njc0OTkxZjc5YTg3OWFhOTNjZjZlNjVkY2ZiNQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
OGQwMDk2Y2YyMThkNDc3MmEyNWJmZmJmZTM1ZjkxYmQ3NGM0NDk5YWMxMjg5
|
10
|
+
ZDgyNDI4OWRhYWY0NzJiNTRmYTYxMTMxZTZhNGIwZTg5ZTdiOTdhZmJhMjFi
|
11
|
+
NGNjZjYyMjRiZDc2ODRmMzA0MmViMjI5NmE0NGU3YmY0ZDUwNjA=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
YzUxOTg2ZGJkNjFiZGZlM2VkNTUxNmRjNDMwMGRhY2IyMmJmMTkwN2ZhOTI5
|
14
|
+
YzgwYzZkNWJjNzAwYzRkNzNlNWNkNGRhZWVlYjcxNTY4ODY4NzMxNTk1ZWUy
|
15
|
+
YTFhNjMyYWViZWRhNmMwMDAzYTJjYzM5OTBmNmMwNWJjMjk0NGQ=
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Timeloop
|
1
|
+
# Timeloop [](https://codeclimate.com/github/pinoss/timeloop) [](https://travis-ci.org/pinoss/timeloop) [](https://coveralls.io/r/pinoss/timeloop?branch=master) [](http://badge.fury.io/rb/timeloop)
|
2
2
|
|
3
3
|
Timeloop is a simple Ruby gem that provides loop with time interval inspired on 'every' method from whenever gem.
|
4
4
|
|
@@ -59,7 +59,7 @@ end
|
|
59
59
|
You can also specify how many times your block will be evaluated:
|
60
60
|
|
61
61
|
```ruby
|
62
|
-
every 10.seconds,
|
62
|
+
every 10.seconds, maximum: 4.times do |i|
|
63
63
|
puts i
|
64
64
|
end
|
65
65
|
|
@@ -71,7 +71,7 @@ end
|
|
71
71
|
# 3
|
72
72
|
# => 4
|
73
73
|
|
74
|
-
every 'second',
|
74
|
+
every 'second', maximum: 3 do |i|
|
75
75
|
puts 'You will see me only 3 times.'
|
76
76
|
end
|
77
77
|
|
data/lib/timeloop.rb
CHANGED
@@ -1,7 +1,62 @@
|
|
1
1
|
require 'timeloop/core_ext'
|
2
|
-
require 'timeloop/every'
|
3
2
|
require 'timeloop/version'
|
4
3
|
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
module Kernel
|
5
|
+
def every(value, opts = {})
|
6
|
+
maximum = parse_maximum_value(opts.fetch(:maximum)) if opts.key? :maximum
|
7
|
+
frequency = parse_frequency(value)
|
8
|
+
|
9
|
+
if maximum.nil?
|
10
|
+
i = 0
|
11
|
+
loop do
|
12
|
+
yield(i) if block_given?
|
13
|
+
sleep frequency
|
14
|
+
|
15
|
+
i += 1
|
16
|
+
end
|
17
|
+
else
|
18
|
+
maximum.times do |i|
|
19
|
+
yield(i) if block_given?
|
20
|
+
sleep frequency
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def parse_frequency(frequency)
|
28
|
+
case frequency
|
29
|
+
when Numeric
|
30
|
+
frequency
|
31
|
+
when :second, 'second'
|
32
|
+
1.second
|
33
|
+
when :minute, 'second'
|
34
|
+
1.minute
|
35
|
+
when :hour, 'hour'
|
36
|
+
1.hour
|
37
|
+
when :day, 'day'
|
38
|
+
1.day
|
39
|
+
when :month, 'month'
|
40
|
+
1.month
|
41
|
+
when :year, 'year'
|
42
|
+
1.year
|
43
|
+
else
|
44
|
+
fail ArgumentError.new('wrong type of argument (should be a Numeric, Symbol or String)')
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def parse_maximum_value(maximum)
|
49
|
+
case maximum
|
50
|
+
when Enumerator
|
51
|
+
maximum.count
|
52
|
+
when Integer
|
53
|
+
maximum
|
54
|
+
else
|
55
|
+
fail ArgumentError.new('wrong type of argument (should be an Enumerator or Integer)')
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
class Object
|
61
|
+
include Kernel
|
62
|
+
end
|
data/lib/timeloop/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
data/timeloop.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: timeloop
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Maciej Paruszewski
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-07-
|
11
|
+
date: 2014-07-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - ! '>='
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: coveralls
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ! '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
55
69
|
description:
|
56
70
|
email:
|
57
71
|
- maciek.paruszewski@gmail.com
|
@@ -72,7 +86,6 @@ files:
|
|
72
86
|
- lib/timeloop/core_ext/integer/time.rb
|
73
87
|
- lib/timeloop/core_ext/numeric.rb
|
74
88
|
- lib/timeloop/core_ext/numeric/time.rb
|
75
|
-
- lib/timeloop/every.rb
|
76
89
|
- lib/timeloop/version.rb
|
77
90
|
- spec/spec_helper.rb
|
78
91
|
- spec/unit/core_ext/integer_spec.rb
|
data/lib/timeloop/every.rb
DELETED
@@ -1,58 +0,0 @@
|
|
1
|
-
module Timeloop
|
2
|
-
module Every
|
3
|
-
|
4
|
-
def every(value, opts = {})
|
5
|
-
maximum = parse_maximum_value(opts.fetch(:maximum)) if opts.key? :maximum
|
6
|
-
frequency = parse_frequency(value)
|
7
|
-
|
8
|
-
if maximum.nil?
|
9
|
-
i = 0
|
10
|
-
loop do
|
11
|
-
yield(i) if block_given?
|
12
|
-
sleep frequency
|
13
|
-
|
14
|
-
i += 1
|
15
|
-
end
|
16
|
-
else
|
17
|
-
maximum.times do |i|
|
18
|
-
yield(i) if block_given?
|
19
|
-
sleep frequency
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
private
|
25
|
-
|
26
|
-
def parse_frequency(frequency)
|
27
|
-
case frequency
|
28
|
-
when Numeric
|
29
|
-
frequency
|
30
|
-
when :second, 'second'
|
31
|
-
1.second
|
32
|
-
when :minute, 'second'
|
33
|
-
1.minute
|
34
|
-
when :hour, 'hour'
|
35
|
-
1.hour
|
36
|
-
when :day, 'day'
|
37
|
-
1.day
|
38
|
-
when :month, 'month'
|
39
|
-
1.month
|
40
|
-
when :year, 'year'
|
41
|
-
1.year
|
42
|
-
else
|
43
|
-
fail ArgumentError.new('wrong type of argument (should be a Numeric, Symbol or String)')
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
def parse_maximum_value(maximum)
|
48
|
-
case maximum
|
49
|
-
when Enumerator
|
50
|
-
maximum.count
|
51
|
-
when Integer
|
52
|
-
maximum
|
53
|
-
else
|
54
|
-
fail ArgumentError.new('wrong type of argument (should be an Enumerator or Integer)')
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|