progress 2.1.1 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/progress/with_progress.rb +3 -2
- data/progress.gemspec +1 -1
- data/spec/progress_spec.rb +16 -0
- metadata +4 -4
@@ -4,6 +4,8 @@ class Progress
|
|
4
4
|
class WithProgress
|
5
5
|
include Enumerable
|
6
6
|
|
7
|
+
attr_reader :enumerable, :title
|
8
|
+
|
7
9
|
# initialize with object responding to each, title and optional length
|
8
10
|
# if block is provided, it is passed to each
|
9
11
|
def initialize(enumerable, title, length = nil, &block)
|
@@ -37,8 +39,7 @@ class Progress
|
|
37
39
|
|
38
40
|
# returns self but changes title
|
39
41
|
def with_progress(title = nil, &block)
|
40
|
-
@title
|
41
|
-
block ? each(&block) : self
|
42
|
+
self.class.new(@enumerable, title, @length, &block)
|
42
43
|
end
|
43
44
|
end
|
44
45
|
end
|
data/progress.gemspec
CHANGED
data/spec/progress_spec.rb
CHANGED
@@ -231,6 +231,22 @@ describe Progress do
|
|
231
231
|
@a.with_progress('Hello').each_cons(3){ |values| with_progress << values }
|
232
232
|
without_progress.should == with_progress
|
233
233
|
end
|
234
|
+
|
235
|
+
describe "with_progress.with_progress" do
|
236
|
+
it "should not change existing instance" do
|
237
|
+
wp = @a.with_progress('hello')
|
238
|
+
proc{ wp.with_progress('world') }.should_not change(wp, :title)
|
239
|
+
end
|
240
|
+
|
241
|
+
it "should create new instance with different title when called on WithProgress" do
|
242
|
+
wp = @a.with_progress('hello')
|
243
|
+
wp_wp = wp.with_progress('world')
|
244
|
+
wp.title.should == 'hello'
|
245
|
+
wp_wp.title.should == 'world'
|
246
|
+
wp_wp.should_not == wp
|
247
|
+
wp_wp.enumerable.should == wp.enumerable
|
248
|
+
end
|
249
|
+
end
|
234
250
|
end
|
235
251
|
end
|
236
252
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: progress
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 7
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 2
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 2.
|
8
|
+
- 2
|
9
|
+
- 0
|
10
|
+
version: 2.2.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Ivan Kuchin
|