batch 0.0.2 → 0.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.
- data/README.markdown +44 -1
- data/batch.gemspec +1 -1
- data/lib/batch.rb +8 -3
- data/test/batch_test.rb +20 -1
- data/test/test_helper.rb +2 -1
- metadata +3 -3
data/README.markdown
CHANGED
@@ -1,7 +1,16 @@
|
|
1
1
|
Batch
|
2
2
|
=====
|
3
3
|
|
4
|
-
|
4
|
+
Keep your batch jobs under control.
|
5
|
+
|
6
|
+
Description
|
7
|
+
-----------
|
8
|
+
|
9
|
+
Say you have a thousand images to process. You write a script, fire it and go
|
10
|
+
to bed, only to realize the morning after that and exception was raised and the
|
11
|
+
script was aborted. Well, no more frustration: now you can use Batch to make
|
12
|
+
sure your script continues working despite those exceptions, and you can now
|
13
|
+
get a nice report to read while you drink your morning coffee.
|
5
14
|
|
6
15
|
Usage
|
7
16
|
-----
|
@@ -34,3 +43,37 @@ don't get interrupted right after you go to bed:
|
|
34
43
|
Some errors occured:
|
35
44
|
|
36
45
|
# ... detailed exceptions here
|
46
|
+
|
47
|
+
You can determine the line width by setting the environment variable
|
48
|
+
`BATCH_WIDTH`, which defaults to 75.
|
49
|
+
|
50
|
+
Installation
|
51
|
+
------------
|
52
|
+
|
53
|
+
$ gem install batch
|
54
|
+
|
55
|
+
License
|
56
|
+
-------
|
57
|
+
|
58
|
+
Copyright (c) 2010 Damian Janowski and Michel Martens
|
59
|
+
|
60
|
+
Permission is hereby granted, free of charge, to any person
|
61
|
+
obtaining a copy of this software and associated documentation
|
62
|
+
files (the "Software"), to deal in the Software without
|
63
|
+
restriction, including without limitation the rights to use,
|
64
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
65
|
+
copies of the Software, and to permit persons to whom the
|
66
|
+
Software is furnished to do so, subject to the following
|
67
|
+
conditions:
|
68
|
+
|
69
|
+
The above copyright notice and this permission notice shall be
|
70
|
+
included in all copies or substantial portions of the Software.
|
71
|
+
|
72
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
73
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
74
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
75
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
76
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
77
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
78
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
79
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
data/batch.gemspec
CHANGED
data/lib/batch.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
class Batch
|
2
|
-
VERSION = "0.0.
|
2
|
+
VERSION = "0.0.3"
|
3
3
|
|
4
4
|
attr :enumerable
|
5
5
|
|
6
6
|
def initialize(enumerable)
|
7
7
|
@enumerable = enumerable
|
8
|
+
@width = (ENV["BATCH_WIDTH"] || 75).to_i
|
8
9
|
end
|
9
10
|
|
10
11
|
def each(&block)
|
@@ -45,10 +46,14 @@ class Batch
|
|
45
46
|
$stderr.puts "\nSome errors occured:\n\n"
|
46
47
|
|
47
48
|
@errors.each do |item, error|
|
48
|
-
|
49
|
+
report_error(item, error)
|
49
50
|
end
|
50
51
|
end
|
51
52
|
|
53
|
+
def report_error(item, error)
|
54
|
+
$stderr.puts "#{item.inspect}: #{error}\n"
|
55
|
+
end
|
56
|
+
|
52
57
|
def total
|
53
58
|
@enumerable.size
|
54
59
|
end
|
@@ -62,7 +67,7 @@ class Batch
|
|
62
67
|
end
|
63
68
|
|
64
69
|
def eol?
|
65
|
-
@current %
|
70
|
+
@current % @width == 0 || @current == total
|
66
71
|
end
|
67
72
|
|
68
73
|
def self.each(enumerable, &block)
|
data/test/batch_test.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require File.expand_path("./test_helper", File.dirname(__FILE__))
|
2
4
|
|
3
5
|
class BatchTest < Test::Unit::TestCase
|
4
6
|
should "report" do
|
@@ -40,4 +42,21 @@ EOS
|
|
40
42
|
assert_equal expected_stdout.rstrip, stdout.rstrip
|
41
43
|
assert_equal expected_stderr.rstrip, stderr.rstrip
|
42
44
|
end
|
45
|
+
|
46
|
+
should "use BATCH_WIDTH" do
|
47
|
+
ENV["BATCH_WIDTH"] = "40"
|
48
|
+
stdout, _ = capture do
|
49
|
+
Batch.each((1..80).to_a) do |item|
|
50
|
+
item + 1
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
expected = <<-EOS
|
55
|
+
0% ........................................
|
56
|
+
50% ........................................
|
57
|
+
100%
|
58
|
+
EOS
|
59
|
+
|
60
|
+
assert_equal expected.rstrip, stdout.rstrip
|
61
|
+
end
|
43
62
|
end
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 3
|
9
|
+
version: 0.0.3
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Damian Janowski
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-09-20 00:00:00 -03:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|