progress 3.0.0 → 3.0.1

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
- OWNkMGE2NDNkOTU0NmM5NzVlN2JkNWQ5YjdiMjY2ZjJlZWRjMTA5ZQ==
4
+ MzcwYjdhOTE5ZDQ5NWViMWM3NzY2ZmQ3YTQ5MGUzNDI2Njk3MDQ4Yw==
5
5
  data.tar.gz: !binary |-
6
- MmYyYTQ1NGFiNzliM2VhNzE1OWI2OGE0OWZkOWVmMDI2ZjMzNmRmYg==
6
+ ZGMyYjk3MTg1N2VlYjBiNWY1NTJlMjdlNmMzNzI1NWY0NmE3ZThjNQ==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- NWQ5ODQyNTg5YTg4MDhjZGI1Y2EzZmQ1ZTA2NGMzNzRmNzg0NWFjOTJiZDdk
10
- OTZkYzIzMDIwMzIxZjhlNTQ1M2M5MDAyOGQ3NmQ5YTM1ZWIxODIxYmQyZDNh
11
- OGUwNDlmOWE3MTNlMjAwYmEzN2EyNTEyZjA0YTNjMzVkNGJkNTc=
9
+ NDQyNzI2YmVlZWQ1YmU2OGIyMGY5M2I3ODFhZTBiYzU4YTZhNjdlM2FmOGI5
10
+ MzdjM2E3NDcxZThhMzE2MDEwNTIzOGI5NmM5YzU3YzdiM2UxMGZiMzJhZThi
11
+ MzZmZDVkYWQ2ZmFiZDZlNTNmNmUxNGRmNzJhZGNiZDkzNTZlZTU=
12
12
  data.tar.gz: !binary |-
13
- NTJmNjY4YzJlMmVlYzM2MDMyNjk4NDNjMjFkYTIyMmFiNTQ5NDdiMTkzYTg3
14
- ODY4MmU5MTNlMGFjZGViZjhiNGZjOGZjMzBiYTM4MDYzODE3MTY3ZGVkNjJm
15
- ZTFjZmMxZTI3ZTUwZDI2ZTQ1NTQ5MjdlZjVkNDI1NjY0NGJjNzM=
13
+ N2VkZThiYjYxMzhhOGM4ZjkzZDllNzBkYzU4Y2Q5ZDVmN2MyNmY2ZmY1YzQ4
14
+ NWExNzdiOWUxMWEyMjdiODBlMWIwNTJkYjEyZmM5MGMxZDFiZjdiODEwYzIx
15
+ OTdjNjU0ZTFhODMxYzAwNjQzMjcyNjM4ZmM5NjMxOTMyNjM3OGM=
data/.travis.yml CHANGED
@@ -6,7 +6,5 @@ rvm:
6
6
  - 2.0.0
7
7
  - jruby-18mode
8
8
  - jruby-19mode
9
- - rbx-18mode
10
- - rbx-19mode
11
9
  - ree
12
10
  script: "bundle exec rspec"
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2010-2013 Ivan Kuchin
1
+ Copyright (c) 2010-2014 Ivan Kuchin
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.markdown CHANGED
@@ -133,4 +133,4 @@ Or if you know that B runs 9 times faster than C:
133
133
 
134
134
  ## Copyright
135
135
 
136
- Copyright (c) 2010-2013 Ivan Kuchin. See LICENSE.txt for details.
136
+ Copyright (c) 2010-2014 Ivan Kuchin. See LICENSE.txt for details.
@@ -1,22 +1,47 @@
1
1
  require 'progress'
2
- require 'delegate'
3
2
 
4
3
  class Progress
5
- class WithProgress < Delegator
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
- # each object with progress
19
- def each
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
- @enumerable.each.to_a
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
- Progress.start(@title, length) do
46
- enumerable.each do |object|
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
- yield object
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
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'progress'
5
- s.version = '3.0.0'
5
+ s.version = '3.0.1'
6
6
  s.summary = %q{Show progress of long running tasks}
7
7
  s.homepage = "http://github.com/toy/#{s.name}"
8
8
  s.authors = ['Ivan Kuchin']
@@ -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.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: 2013-08-20 00:00:00.000000000 Z
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: