progress 0.0.8.1 → 0.0.9.0
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/Manifest +1 -3
- data/README.rdoc +28 -3
- data/Rakefile +1 -1
- data/VERSION.yml +1 -1
- data/lib/progress/enumerable.rb +19 -14
- data/lib/progress/with_progress.rb +41 -0
- data/lib/progress.rb +9 -14
- data/progress.gemspec +5 -6
- data/spec/progress_spec.rb +43 -10
- metadata +5 -6
- data/script/console +0 -10
- data/script/destroy +0 -14
- data/script/generate +0 -14
data/Manifest
CHANGED
@@ -1,13 +1,11 @@
|
|
1
1
|
CHANGELOG
|
2
2
|
lib/progress/enumerable.rb
|
3
3
|
lib/progress/integer.rb
|
4
|
+
lib/progress/with_progress.rb
|
4
5
|
lib/progress.rb
|
5
6
|
Manifest
|
6
7
|
Rakefile
|
7
8
|
README.rdoc
|
8
|
-
script/console
|
9
|
-
script/destroy
|
10
|
-
script/generate
|
11
9
|
spec/progress_spec.rb
|
12
10
|
spec/spec.opts
|
13
11
|
spec/spec_helper.rb
|
data/README.rdoc
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
|
7
7
|
Class to show progress during console script run
|
8
8
|
|
9
|
-
== FEATURES
|
9
|
+
== FEATURES:
|
10
10
|
|
11
11
|
* Progress
|
12
12
|
* Enclosed progress
|
@@ -14,7 +14,32 @@ Class to show progress during console script run
|
|
14
14
|
== SYNOPSIS:
|
15
15
|
|
16
16
|
1000.times_with_progress('Wait') do |time|
|
17
|
-
|
17
|
+
puts time
|
18
|
+
end
|
19
|
+
|
20
|
+
[1, 2, 3].with_progress('Wait').each do |i|
|
21
|
+
puts i
|
22
|
+
end
|
23
|
+
|
24
|
+
(1..100).with_progress('Wait').each do |i|
|
25
|
+
puts i
|
26
|
+
end
|
27
|
+
|
28
|
+
{
|
29
|
+
:a => 'a',
|
30
|
+
:b => 'b',
|
31
|
+
:c => 'c',
|
32
|
+
:d => 'd',
|
33
|
+
}.with_progress('Wait').each do |k, v|
|
34
|
+
puts "#{k} => #{v}"
|
35
|
+
end
|
36
|
+
|
37
|
+
(1..10).with_progress('Outer').map do |a|
|
38
|
+
(1..10).with_progress('Middle').map do |b|
|
39
|
+
(1..10).with_progress('Inner').map do |c|
|
40
|
+
[a, b, c]
|
41
|
+
end
|
42
|
+
end
|
18
43
|
end
|
19
44
|
|
20
45
|
== REQUIREMENTS:
|
@@ -29,7 +54,7 @@ Class to show progress during console script run
|
|
29
54
|
|
30
55
|
(The MIT License)
|
31
56
|
|
32
|
-
Copyright (c) 2008 toy
|
57
|
+
Copyright (c) 2008 toy
|
33
58
|
|
34
59
|
Permission is hereby granted, free of charge, to any person obtaining
|
35
60
|
a copy of this software and associated documentation files (the
|
data/Rakefile
CHANGED
data/VERSION.yml
CHANGED
@@ -1 +1 @@
|
|
1
|
-
[0, 0,
|
1
|
+
[0, 0, 9, 0]
|
data/lib/progress/enumerable.rb
CHANGED
@@ -1,16 +1,25 @@
|
|
1
|
+
require 'enumerator'
|
1
2
|
module Enumerable
|
3
|
+
# executes any Enumerable method with progress
|
4
|
+
# note that methods which don't necessarily go through all items (like find or any?) will not show 100%
|
5
|
+
# ==== Example
|
6
|
+
# [1, 2, 3].with_progress('Numbers').each do |number|
|
7
|
+
# sleep(number)
|
8
|
+
# end
|
9
|
+
# [1, 2, 3].with_progress('Numbers').each_cons(2) do |numbers|
|
10
|
+
# p numbers
|
11
|
+
# end
|
12
|
+
def with_progress(title)
|
13
|
+
Progress::WithProgress.new(self, title)
|
14
|
+
end
|
15
|
+
|
2
16
|
# note that Progress.step is called automatically
|
3
17
|
# ==== Example
|
4
18
|
# [1, 2, 3].each_with_progress('Numbers') do |number|
|
5
19
|
# sleep(number)
|
6
20
|
# end
|
7
|
-
def each_with_progress(
|
8
|
-
|
9
|
-
each do |item|
|
10
|
-
yield item
|
11
|
-
Progress.step
|
12
|
-
end
|
13
|
-
end
|
21
|
+
def each_with_progress(title, *args, &block)
|
22
|
+
with_progress(title).each(*args, &block)
|
14
23
|
end
|
15
24
|
|
16
25
|
# note that Progress.step is called automatically
|
@@ -18,12 +27,8 @@ module Enumerable
|
|
18
27
|
# [1, 2, 3].each_with_index_and_progress('Numbers') do |number, index|
|
19
28
|
# sleep(number)
|
20
29
|
# end
|
21
|
-
def each_with_index_and_progress(
|
22
|
-
|
23
|
-
each_with_index do |item, index|
|
24
|
-
yield item, index
|
25
|
-
Progress.step
|
26
|
-
end
|
27
|
-
end
|
30
|
+
def each_with_index_and_progress(title, *args, &block)
|
31
|
+
with_progress(title).each_with_index(*args, &block)
|
28
32
|
end
|
33
|
+
|
29
34
|
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'delegate'
|
2
|
+
|
3
|
+
class Progress
|
4
|
+
class WithProgress
|
5
|
+
attr_reader :object, :title
|
6
|
+
def initialize(object, title)
|
7
|
+
@object = Progress::Enhancer.new(object)
|
8
|
+
@title = title
|
9
|
+
end
|
10
|
+
|
11
|
+
def with_progress(title)
|
12
|
+
self
|
13
|
+
end
|
14
|
+
|
15
|
+
def method_missing(method, *args, &block)
|
16
|
+
Progress.start(title, object.length) do
|
17
|
+
object.send(method, *args, &block)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class Enhancer < SimpleDelegator
|
23
|
+
include Enumerable
|
24
|
+
def each(*args, &block)
|
25
|
+
__getobj__.each(*args) do |*yielded|
|
26
|
+
block.call(*yielded)
|
27
|
+
Progress.step
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def length
|
32
|
+
if __getobj__.respond_to?(:length) && !__getobj__.is_a?(String)
|
33
|
+
__getobj__.length
|
34
|
+
elsif __getobj__.respond_to?(:to_a)
|
35
|
+
__getobj__.to_a.length
|
36
|
+
else
|
37
|
+
__getobj__.inject(0){ |length, obj| length + 1 }
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/lib/progress.rb
CHANGED
@@ -31,8 +31,8 @@ class Progress
|
|
31
31
|
# Progress.start('Test', 1000, :lines => true) do
|
32
32
|
# 1000.times{ Progress.step }
|
33
33
|
# end
|
34
|
-
def self.start(
|
35
|
-
levels << new(
|
34
|
+
def self.start(title, total = 1, options = {})
|
35
|
+
levels << new(title, total, levels.length, options)
|
36
36
|
print_message
|
37
37
|
if block_given?
|
38
38
|
result = yield
|
@@ -41,8 +41,9 @@ class Progress
|
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
|
-
|
45
|
-
|
44
|
+
attr_reader :message, :options
|
45
|
+
def initialize(title, total, level, options) # :nodoc:
|
46
|
+
@title = title + ': %s'
|
46
47
|
@total = total
|
47
48
|
@level = level
|
48
49
|
@options = options
|
@@ -63,14 +64,6 @@ class Progress
|
|
63
64
|
self.message = percent
|
64
65
|
end
|
65
66
|
|
66
|
-
def message # :nodoc:
|
67
|
-
@message
|
68
|
-
end
|
69
|
-
|
70
|
-
def options # :nodoc:
|
71
|
-
@options
|
72
|
-
end
|
73
|
-
|
74
67
|
protected
|
75
68
|
|
76
69
|
def percent
|
@@ -79,7 +72,7 @@ protected
|
|
79
72
|
|
80
73
|
def message=(s)
|
81
74
|
formatted = s.ljust(6)[0, 6]
|
82
|
-
@message = @
|
75
|
+
@message = @title % formatted
|
83
76
|
end
|
84
77
|
|
85
78
|
module ClassMethods
|
@@ -93,7 +86,7 @@ protected
|
|
93
86
|
@io.puts if levels.empty?
|
94
87
|
end
|
95
88
|
|
96
|
-
def io=(io)
|
89
|
+
def io=(io)
|
97
90
|
@io = io
|
98
91
|
end
|
99
92
|
|
@@ -118,5 +111,7 @@ protected
|
|
118
111
|
extend ClassMethods
|
119
112
|
end
|
120
113
|
|
114
|
+
require 'progress/with_progress'
|
115
|
+
|
121
116
|
require 'progress/enumerable'
|
122
117
|
require 'progress/integer'
|
data/progress.gemspec
CHANGED
@@ -2,21 +2,20 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{progress}
|
5
|
-
s.version = "0.0.
|
5
|
+
s.version = "0.0.9.0"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["toy"]
|
9
|
-
s.date = %q{2009-
|
9
|
+
s.date = %q{2009-07-20}
|
10
10
|
s.description = %q{A library to show progress of long running tasks.}
|
11
11
|
s.email = %q{}
|
12
|
-
s.extra_rdoc_files = ["CHANGELOG", "lib/progress/enumerable.rb", "lib/progress/integer.rb", "lib/progress.rb", "README.rdoc", "tasks/rspec.rake"]
|
13
|
-
s.files = ["CHANGELOG", "lib/progress/enumerable.rb", "lib/progress/integer.rb", "lib/progress.rb", "Manifest", "Rakefile", "README.rdoc", "
|
14
|
-
s.has_rdoc = true
|
12
|
+
s.extra_rdoc_files = ["CHANGELOG", "lib/progress/enumerable.rb", "lib/progress/integer.rb", "lib/progress/with_progress.rb", "lib/progress.rb", "README.rdoc", "tasks/rspec.rake"]
|
13
|
+
s.files = ["CHANGELOG", "lib/progress/enumerable.rb", "lib/progress/integer.rb", "lib/progress/with_progress.rb", "lib/progress.rb", "Manifest", "Rakefile", "README.rdoc", "spec/progress_spec.rb", "spec/spec.opts", "spec/spec_helper.rb", "tasks/rspec.rake", "VERSION.yml", "progress.gemspec"]
|
15
14
|
s.homepage = %q{}
|
16
15
|
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Progress", "--main", "README.rdoc"]
|
17
16
|
s.require_paths = ["lib"]
|
18
17
|
s.rubyforge_project = %q{progress}
|
19
|
-
s.rubygems_version = %q{1.3.
|
18
|
+
s.rubygems_version = %q{1.3.4}
|
20
19
|
s.summary = %q{A library to show progress of long running tasks.}
|
21
20
|
|
22
21
|
if s.respond_to? :specification_version then
|
data/spec/progress_spec.rb
CHANGED
@@ -5,7 +5,7 @@ describe Progress do
|
|
5
5
|
@io = StringIO.new
|
6
6
|
Progress.io = @io
|
7
7
|
end
|
8
|
-
|
8
|
+
|
9
9
|
def io_pop
|
10
10
|
@io.seek(0)
|
11
11
|
s = @io.read
|
@@ -30,7 +30,7 @@ describe Progress do
|
|
30
30
|
Progress.stop
|
31
31
|
verify_output_after_stop
|
32
32
|
end
|
33
|
-
|
33
|
+
|
34
34
|
it "should show valid output for block version" do
|
35
35
|
Progress.start('Test', 1000) do
|
36
36
|
1000.times do |i|
|
@@ -43,16 +43,16 @@ describe Progress do
|
|
43
43
|
|
44
44
|
describe Enumerable do
|
45
45
|
before :each do
|
46
|
-
@a =
|
46
|
+
@a = (0...1000).to_a
|
47
47
|
end
|
48
48
|
|
49
49
|
describe 'with each_with_progress' do
|
50
50
|
it "should not break each" do
|
51
|
-
|
51
|
+
a = []
|
52
52
|
@a.each_with_progress('Test') do |n|
|
53
|
-
|
54
|
-
c += 1
|
53
|
+
a << n
|
55
54
|
end
|
55
|
+
a.should == @a
|
56
56
|
end
|
57
57
|
|
58
58
|
it "should show valid output for each_with_progress" do
|
@@ -65,12 +65,12 @@ describe Progress do
|
|
65
65
|
|
66
66
|
describe 'with each_with_index_and_progress' do
|
67
67
|
it "should not break each_with_index" do
|
68
|
-
|
68
|
+
a = []
|
69
69
|
@a.each_with_index_and_progress('Test') do |n, i|
|
70
|
-
n.should ==
|
71
|
-
|
72
|
-
c += 1
|
70
|
+
n.should == i
|
71
|
+
a << n
|
73
72
|
end
|
73
|
+
a.should == @a
|
74
74
|
end
|
75
75
|
|
76
76
|
it "should show valid output for each_with_progress" do
|
@@ -80,6 +80,39 @@ describe Progress do
|
|
80
80
|
verify_output_after_stop
|
81
81
|
end
|
82
82
|
end
|
83
|
+
|
84
|
+
describe 'with with_progress' do
|
85
|
+
it "should not break each" do
|
86
|
+
a = []
|
87
|
+
@a.with_progress('Test').each do |n|
|
88
|
+
a << n
|
89
|
+
end
|
90
|
+
a.should == @a
|
91
|
+
end
|
92
|
+
|
93
|
+
it "should not break any?" do
|
94
|
+
@a.with_progress('Hello').find{ |n| n == 100 }.should == @a.find{ |n| n == 100 }
|
95
|
+
@a.with_progress('Hello').find{ |n| n == 10000 }.should == @a.find{ |n| n == 10000 }
|
96
|
+
default = proc{ 'default' }
|
97
|
+
@a.with_progress('Hello').find(default){ |n| n == 10000 }.should == @a.find(default){ |n| n == 10000 }
|
98
|
+
end
|
99
|
+
|
100
|
+
it "should not break map" do
|
101
|
+
@a.with_progress('Hello').map{ |n| n * n }.should == @a.map{ |n| n * n }
|
102
|
+
end
|
103
|
+
|
104
|
+
it "should not break grep" do
|
105
|
+
@a.with_progress('Hello').grep(100).should == @a.grep(100)
|
106
|
+
end
|
107
|
+
|
108
|
+
it "should not break each_cons" do
|
109
|
+
without_progress = []
|
110
|
+
@a.each_cons(3){ |values| without_progress << values }
|
111
|
+
with_progress = []
|
112
|
+
@a.with_progress('Hello').each_cons(3){ |values| with_progress << values }
|
113
|
+
without_progress.should == with_progress
|
114
|
+
end
|
115
|
+
end
|
83
116
|
end
|
84
117
|
|
85
118
|
describe Integer do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: progress
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- toy
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-07-20 00:00:00 +04:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -23,6 +23,7 @@ extra_rdoc_files:
|
|
23
23
|
- CHANGELOG
|
24
24
|
- lib/progress/enumerable.rb
|
25
25
|
- lib/progress/integer.rb
|
26
|
+
- lib/progress/with_progress.rb
|
26
27
|
- lib/progress.rb
|
27
28
|
- README.rdoc
|
28
29
|
- tasks/rspec.rake
|
@@ -30,13 +31,11 @@ files:
|
|
30
31
|
- CHANGELOG
|
31
32
|
- lib/progress/enumerable.rb
|
32
33
|
- lib/progress/integer.rb
|
34
|
+
- lib/progress/with_progress.rb
|
33
35
|
- lib/progress.rb
|
34
36
|
- Manifest
|
35
37
|
- Rakefile
|
36
38
|
- README.rdoc
|
37
|
-
- script/console
|
38
|
-
- script/destroy
|
39
|
-
- script/generate
|
40
39
|
- spec/progress_spec.rb
|
41
40
|
- spec/spec.opts
|
42
41
|
- spec/spec_helper.rb
|
@@ -72,7 +71,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
72
71
|
requirements: []
|
73
72
|
|
74
73
|
rubyforge_project: progress
|
75
|
-
rubygems_version: 1.3.
|
74
|
+
rubygems_version: 1.3.4
|
76
75
|
signing_key:
|
77
76
|
specification_version: 3
|
78
77
|
summary: A library to show progress of long running tasks.
|
data/script/console
DELETED
@@ -1,10 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# File: script/console
|
3
|
-
irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
|
4
|
-
|
5
|
-
libs = " -r irb/completion"
|
6
|
-
# Perhaps use a console_lib to store any extra methods I may want available in the cosole
|
7
|
-
# libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
|
8
|
-
libs << " -r #{File.dirname(__FILE__) + '/../lib/progress.rb'}"
|
9
|
-
puts "Loading progress gem"
|
10
|
-
exec "#{irb} #{libs} --simple-prompt"
|
data/script/destroy
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
3
|
-
|
4
|
-
begin
|
5
|
-
require 'rubigen'
|
6
|
-
rescue LoadError
|
7
|
-
require 'rubygems'
|
8
|
-
require 'rubigen'
|
9
|
-
end
|
10
|
-
require 'rubigen/scripts/destroy'
|
11
|
-
|
12
|
-
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
13
|
-
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
|
14
|
-
RubiGen::Scripts::Destroy.new.run(ARGV)
|
data/script/generate
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
3
|
-
|
4
|
-
begin
|
5
|
-
require 'rubigen'
|
6
|
-
rescue LoadError
|
7
|
-
require 'rubygems'
|
8
|
-
require 'rubigen'
|
9
|
-
end
|
10
|
-
require 'rubigen/scripts/generate'
|
11
|
-
|
12
|
-
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
13
|
-
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
|
14
|
-
RubiGen::Scripts::Generate.new.run(ARGV)
|