progress 3.0.0 → 3.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/.travis.yml +0 -2
- data/LICENSE.txt +1 -1
- data/README.markdown +1 -1
- data/lib/progress/with_progress.rb +51 -34
- data/progress.gemspec +1 -1
- data/spec/progress_spec.rb +6 -6
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MzcwYjdhOTE5ZDQ5NWViMWM3NzY2ZmQ3YTQ5MGUzNDI2Njk3MDQ4Yw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZGMyYjk3MTg1N2VlYjBiNWY1NTJlMjdlNmMzNzI1NWY0NmE3ZThjNQ==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NDQyNzI2YmVlZWQ1YmU2OGIyMGY5M2I3ODFhZTBiYzU4YTZhNjdlM2FmOGI5
|
10
|
+
MzdjM2E3NDcxZThhMzE2MDEwNTIzOGI5NmM5YzU3YzdiM2UxMGZiMzJhZThi
|
11
|
+
MzZmZDVkYWQ2ZmFiZDZlNTNmNmUxNGRmNzJhZGNiZDkzNTZlZTU=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
N2VkZThiYjYxMzhhOGM4ZjkzZDllNzBkYzU4Y2Q5ZDVmN2MyNmY2ZmY1YzQ4
|
14
|
+
NWExNzdiOWUxMWEyMjdiODBlMWIwNTJkYjEyZmM5MGMxZDFiZjdiODEwYzIx
|
15
|
+
OTdjNjU0ZTFhODMxYzAwNjQzMjcyNjM4ZmM5NjMxOTMyNjM3OGM=
|
data/.travis.yml
CHANGED
data/LICENSE.txt
CHANGED
data/README.markdown
CHANGED
@@ -1,22 +1,47 @@
|
|
1
1
|
require 'progress'
|
2
|
-
require 'delegate'
|
3
2
|
|
4
3
|
class Progress
|
5
|
-
class WithProgress
|
6
|
-
include Enumerable
|
7
|
-
|
4
|
+
class WithProgress
|
8
5
|
attr_reader :enumerable, :title
|
9
6
|
|
10
7
|
# initialize with object responding to each, title and optional length
|
11
8
|
# if block is provided, it is passed to each
|
12
9
|
def initialize(enumerable, title, length = nil, &block)
|
13
|
-
super(enumerable)
|
14
10
|
@enumerable, @title, @length = enumerable, title, length
|
15
11
|
each(&block) if block
|
16
12
|
end
|
17
13
|
|
18
|
-
#
|
19
|
-
def
|
14
|
+
# returns self but changes title
|
15
|
+
def with_progress(title = nil, length = nil, &block)
|
16
|
+
self.class.new(@enumerable, title, length || @length, &block)
|
17
|
+
end
|
18
|
+
|
19
|
+
# befriend with in_threads gem
|
20
|
+
def in_threads(*args, &block)
|
21
|
+
@enumerable.in_threads(*args).with_progress(@title, @length, &block)
|
22
|
+
rescue
|
23
|
+
super
|
24
|
+
end
|
25
|
+
|
26
|
+
def respond_to?(sym, include_private = false)
|
27
|
+
enumerable_method?(method) || super(sym, include_private)
|
28
|
+
end
|
29
|
+
|
30
|
+
def method_missing(method, *args, &block)
|
31
|
+
if enumerable_method?(method)
|
32
|
+
run(method, *args, &block)
|
33
|
+
else
|
34
|
+
super(method, *args, &block)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
protected
|
39
|
+
|
40
|
+
def enumerable_method?(method)
|
41
|
+
method == :each || Enumerable.method_defined?(method)
|
42
|
+
end
|
43
|
+
|
44
|
+
def run(method, *args, &block)
|
20
45
|
enumerable = case
|
21
46
|
when @length
|
22
47
|
@enumerable
|
@@ -26,7 +51,9 @@ class Progress
|
|
26
51
|
Object.const_defined?(:StringIO) && @enumerable.is_a?(StringIO),
|
27
52
|
Object.const_defined?(:TempFile) && @enumerable.is_a?(TempFile)
|
28
53
|
warn "Progress: collecting elements for instance of class #{@enumerable.class}"
|
29
|
-
|
54
|
+
lines = []
|
55
|
+
@enumerable.each{ |line| lines << line }
|
56
|
+
lines
|
30
57
|
else
|
31
58
|
@enumerable
|
32
59
|
end
|
@@ -42,37 +69,27 @@ class Progress
|
|
42
69
|
enumerable.count
|
43
70
|
end
|
44
71
|
|
45
|
-
|
46
|
-
|
72
|
+
if block
|
73
|
+
result = Progress.start(@title, length) do
|
74
|
+
enumerable.send(method, *args) do |*block_args|
|
75
|
+
Progress.step do
|
76
|
+
block.call(*block_args)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
if result.eql?(enumerable)
|
81
|
+
@enumerable
|
82
|
+
else
|
83
|
+
result
|
84
|
+
end
|
85
|
+
else
|
86
|
+
Progress.start(@title) do
|
47
87
|
Progress.step do
|
48
|
-
|
88
|
+
enumerable.send(method, *args)
|
49
89
|
end
|
50
90
|
end
|
51
|
-
@enumerable
|
52
91
|
end
|
53
92
|
end
|
54
93
|
|
55
|
-
# returns self but changes title
|
56
|
-
def with_progress(title = nil, length = nil, &block)
|
57
|
-
self.class.new(@enumerable, title, length || @length, &block)
|
58
|
-
end
|
59
|
-
|
60
|
-
# befriend with in_threads gem
|
61
|
-
def in_threads(*args, &block)
|
62
|
-
@enumerable.in_threads(*args).with_progress(@title, @length, &block)
|
63
|
-
rescue
|
64
|
-
super
|
65
|
-
end
|
66
|
-
|
67
|
-
protected
|
68
|
-
|
69
|
-
def __getobj__
|
70
|
-
@enumerable
|
71
|
-
end
|
72
|
-
|
73
|
-
def __setobj__(obj)
|
74
|
-
@enumerable = obj
|
75
|
-
end
|
76
|
-
|
77
94
|
end
|
78
95
|
end
|
data/progress.gemspec
CHANGED
data/spec/progress_spec.rb
CHANGED
@@ -133,26 +133,26 @@ describe Progress do
|
|
133
133
|
|
134
134
|
it "should call each only once for Array" do
|
135
135
|
enum = [1, 2, 3]
|
136
|
-
enum.should_receive(:each).once
|
136
|
+
enum.should_receive(:each).once.and_return(enum)
|
137
137
|
enum.with_progress.each{ }.should == enum
|
138
138
|
end
|
139
139
|
|
140
140
|
it "should call each only once for Hash" do
|
141
141
|
enum = {1 => 1, 2 => 2, 3 => 3}
|
142
|
-
enum.should_receive(:each).once
|
142
|
+
enum.should_receive(:each).once.and_return(enum)
|
143
143
|
enum.with_progress.each{ }.should == enum
|
144
144
|
end
|
145
145
|
|
146
146
|
it "should call each only once for Set" do
|
147
147
|
enum = [1, 2, 3].to_set
|
148
|
-
enum.should_receive(:each).once
|
148
|
+
enum.should_receive(:each).once.and_return(enum)
|
149
149
|
enum.with_progress.each{ }.should == enum
|
150
150
|
end
|
151
151
|
|
152
152
|
if ''.is_a?(Enumerable) # ruby1.8
|
153
153
|
it "should call each only once for String" do
|
154
154
|
enum = "a\nb\nc"
|
155
|
-
enum.should_receive(:each).once
|
155
|
+
enum.should_receive(:each).once.and_return(enum)
|
156
156
|
without_warnings do
|
157
157
|
enum.with_progress.each{ }.should == enum
|
158
158
|
end
|
@@ -161,7 +161,7 @@ describe Progress do
|
|
161
161
|
|
162
162
|
it "should call each only once for File (IO)" do
|
163
163
|
enum = File.open(__FILE__)
|
164
|
-
enum.should_receive(:each).once
|
164
|
+
enum.should_receive(:each).once.and_return(enum)
|
165
165
|
without_warnings do
|
166
166
|
enum.with_progress.each{ }.should == enum
|
167
167
|
end
|
@@ -169,7 +169,7 @@ describe Progress do
|
|
169
169
|
|
170
170
|
it "should call each only once for StringIO" do
|
171
171
|
enum = StringIO.new("a\nb\nc")
|
172
|
-
enum.should_receive(:each).once
|
172
|
+
enum.should_receive(:each).once.and_return(enum)
|
173
173
|
without_warnings do
|
174
174
|
enum.with_progress.each{ }.should == enum
|
175
175
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: progress
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.
|
4
|
+
version: 3.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ivan Kuchin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-08-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -70,3 +70,4 @@ specification_version: 4
|
|
70
70
|
summary: Show progress of long running tasks
|
71
71
|
test_files:
|
72
72
|
- spec/progress_spec.rb
|
73
|
+
has_rdoc:
|