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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- N2EyYjI2NjY3NTY0OThmNTk3MDdmNzFjZTZmYWQxZWY4NTJkOWFmZA==
4
+ MTMzN2I2ZmE3MGY1MjMyMzY5ZWQxOTNkNDVhMDljYjc0OWQ0MTk5NQ==
5
5
  data.tar.gz: !binary |-
6
- ZjQwMWFhMWM4OGFiNzMxYzJiNGNiOTQ3YzNjODkzNDRmZGU3NGM1ZQ==
6
+ ODYxODZmNWFlOTM5Njc0OTkxZjc5YTg3OWFhOTNjZjZlNjVkY2ZiNQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- N2QxYTgwNGE3M2Q5NjVjODY5OTNiYjdlNDliMjFhYTBmZjkyYWJkNWNmZjFl
10
- ZGZlODA0YWUzMTJhZDIxOGUyN2U4YTkwZGYwOGJlM2FiYTAzM2EzZTRjMzA3
11
- YWZmY2RjN2FlM2QzYWIwMGYyZDlkMWVkOWUwZjdmNWYzMTliNzM=
9
+ OGQwMDk2Y2YyMThkNDc3MmEyNWJmZmJmZTM1ZjkxYmQ3NGM0NDk5YWMxMjg5
10
+ ZDgyNDI4OWRhYWY0NzJiNTRmYTYxMTMxZTZhNGIwZTg5ZTdiOTdhZmJhMjFi
11
+ NGNjZjYyMjRiZDc2ODRmMzA0MmViMjI5NmE0NGU3YmY0ZDUwNjA=
12
12
  data.tar.gz: !binary |-
13
- NGQxYTA5N2M0MzI3ODRlZDY3YzAwYTViZjE2MGUxOGMxYTRlYTQzODY2ODE3
14
- YjFlZDhjZjNhOTZkNjhjY2U2YjhhOTJmYjgyOTk1YzMxNjU5ODA3NDdlYjRl
15
- Yjk3NDkyZGNlOTRlM2U0Nzc4YzBhODRjYTczOWJhNGNhZDI5Mzc=
13
+ YzUxOTg2ZGJkNjFiZGZlM2VkNTUxNmRjNDMwMGRhY2IyMmJmMTkwN2ZhOTI5
14
+ YzgwYzZkNWJjNzAwYzRkNzNlNWNkNGRhZWVlYjcxNTY4ODY4NzMxNTk1ZWUy
15
+ YTFhNjMyYWViZWRhNmMwMDAzYTJjYzM5OTBmNmMwNWJjMjk0NGQ=
data/.travis.yml CHANGED
@@ -1,7 +1,6 @@
1
1
  language: ruby
2
+ script: bundle exec rake
2
3
  rvm:
3
- - '1.9.3'
4
- - '2.0.0'
5
- - '2.1.1'
6
-
7
- script: bundle exec rake spec
4
+ - 1.9.3
5
+ - 2.0.0
6
+ - 2.1.0
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Timeloop
1
+ # Timeloop [![Code Climate](https://codeclimate.com/github/pinoss/timeloop.png)](https://codeclimate.com/github/pinoss/timeloop) [![Build Status](https://travis-ci.org/pinoss/timeloop.svg?branch=master)](https://travis-ci.org/pinoss/timeloop) [![Coverage Status](https://coveralls.io/repos/pinoss/timeloop/badge.png?branch=master)](https://coveralls.io/r/pinoss/timeloop?branch=master) [![Gem Version](https://badge.fury.io/rb/timeloop.svg)](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, maxium: 4.times do |i|
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', maxium: 3 do |i|
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
- class << self
6
- include Timeloop::Every
7
- end
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
@@ -1,3 +1,3 @@
1
1
  module Timeloop
2
- VERSION = '1.0.0'
2
+ VERSION = '1.0.3'
3
3
  end
data/spec/spec_helper.rb CHANGED
@@ -1,6 +1,9 @@
1
1
  require 'bundler/setup'
2
2
  Bundler.setup
3
3
 
4
+ require 'coveralls'
5
+ Coveralls.wear!
6
+
4
7
  require 'timeloop'
5
8
 
6
9
  RSpec.configure do |config|
data/timeloop.gemspec CHANGED
@@ -20,4 +20,5 @@ Gem::Specification.new do |spec|
20
20
  spec.add_development_dependency 'bundler', "~> 1.6"
21
21
  spec.add_development_dependency 'rake'
22
22
  spec.add_development_dependency 'rspec'
23
+ spec.add_development_dependency 'coveralls'
23
24
  end
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.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-16 00:00:00.000000000 Z
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
@@ -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