with_progress 1.0.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.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.travis.yml +12 -0
- data/CHANGELOG.rdoc +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +38 -0
- data/Rakefile +6 -0
- data/lib/with_progress/extensions/enumerable.rb +19 -0
- data/lib/with_progress/version.rb +3 -0
- data/lib/with_progress.rb +9 -0
- data/spec/manual_spec.rb +10 -0
- data/spec/with_progress_spec.rb +28 -0
- data/with_progress.gemspec +27 -0
- metadata +111 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
data.tar.gz: 3f2f0e11796ce29a15547e9b4999764f68690902
|
4
|
+
metadata.gz: 2344dd81e4e3ff3c673ae204b7f099df34a21377
|
5
|
+
SHA512:
|
6
|
+
data.tar.gz: 435603621abd935122315fad2a8834847596d3c7fc27d188d8b402f9bf92a2b529ff31e14bbc2ea3ccdf8a85dd191ce4e5241e96e403111f04fbc5949c47bbba
|
7
|
+
metadata.gz: 4438efe9f53a6e0e919b643bd01b3cf7e158d296745753233bfe0bb85639ce1bea31965fde7e8f30a686a4e945b98e940beaaac874b4f43899c9df1dc6d83696
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/CHANGELOG.rdoc
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Marc-Andre Lafortune
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# with_progress [<img src="https://travis-ci.org/marcandre/with_progress.png?branch=master">](https://travis-ci.org/marcandre/with_progress) [<img src="https://badge.fury.io/rb/with_progress.png" alt="Gem Version" />](http://badge.fury.io/rb/with_progress)
|
2
|
+
|
3
|
+
Brings the great [ruby-progressbar](https://github.com/jfelchner/ruby-progressbar) to `Enumerable`.
|
4
|
+
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
This gem adds the method `Enumerable#with_progress`.
|
8
|
+
|
9
|
+
Calling `with_progress` displays a progress bar while the iteration takes place.
|
10
|
+
|
11
|
+
It uses the [ruby-progressbar](https://github.com/jfelchner/ruby-progressbar) gem and accepts the same options.
|
12
|
+
|
13
|
+
In Ruby 2.0+, most enumerables return a size, so `with_progress` uses that to deduce the `total`, there's no need to specify it:
|
14
|
+
|
15
|
+
42.times.with_progress { do_something } # Will provide {total: 42} option in Ruby 2.0+ and show the right progression
|
16
|
+
|
17
|
+
## Installation
|
18
|
+
|
19
|
+
Add this line to your application's Gemfile:
|
20
|
+
|
21
|
+
gem 'with_progress'
|
22
|
+
|
23
|
+
And then execute:
|
24
|
+
|
25
|
+
$ bundle
|
26
|
+
|
27
|
+
Or install it yourself as:
|
28
|
+
|
29
|
+
$ gem install with_progress
|
30
|
+
|
31
|
+
|
32
|
+
## Contributing
|
33
|
+
|
34
|
+
1. Fork it
|
35
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
36
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
37
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
38
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
module Enumerable
|
2
|
+
def with_progress(options = {})
|
3
|
+
return to_enum(:with_progress, options) { size rescue nil } unless block_given?
|
4
|
+
|
5
|
+
options = WithProgress::DEFAULTS.merge(options)
|
6
|
+
unless options.has_key?(:total)
|
7
|
+
options[:total] = size rescue self.end - self.begin + (exclude_end? ? 0 : 1) rescue nil
|
8
|
+
end
|
9
|
+
|
10
|
+
bar = ProgressBar.create(options)
|
11
|
+
each do |*args|
|
12
|
+
result = yield *args
|
13
|
+
bar.increment
|
14
|
+
result
|
15
|
+
end
|
16
|
+
ensure
|
17
|
+
bar.stop if bar
|
18
|
+
end
|
19
|
+
end
|
data/spec/manual_spec.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'with_progress'
|
2
|
+
|
3
|
+
Enumerator = Enumerable::Enumerator unless Object.const_defined? :Enumerator
|
4
|
+
|
5
|
+
describe "with_progress" do
|
6
|
+
subject { 42.times.to_enum(:map).with_progress(&block) }
|
7
|
+
|
8
|
+
describe 'when called without a block' do
|
9
|
+
let(:block) { nil }
|
10
|
+
|
11
|
+
it { should be_instance_of(Enumerator) }
|
12
|
+
if Enumerator.respond_to? :size
|
13
|
+
its(:size) { should == 42 }
|
14
|
+
end
|
15
|
+
it "works" do
|
16
|
+
subject.each{|i| i + 10}.should == [*10...52]
|
17
|
+
end
|
18
|
+
it "can be interrupted" do
|
19
|
+
subject.each{|i| break -i if i >= 4; sleep 0.1; i + 10}.should == -4
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe 'when called with a block' do
|
24
|
+
let(:block) {Proc.new{|i| i + 10} }
|
25
|
+
|
26
|
+
it { should == [*10...52] }
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'with_progress/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "with_progress"
|
8
|
+
spec.version = WithProgress::VERSION
|
9
|
+
spec.authors = ["Marc-Andre Lafortune"]
|
10
|
+
spec.email = ["github@marc-andre.ca"]
|
11
|
+
spec.description = %q{progressbar for enumerables}
|
12
|
+
spec.summary = %q{progressbar for enumerables}
|
13
|
+
spec.homepage = "http://github.com/marcandre/with_progress"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency 'ruby-progressbar', '~> 1.4'
|
22
|
+
spec.add_dependency 'backports', '~> 3.5'
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
25
|
+
spec.add_development_dependency "rake"
|
26
|
+
spec.add_development_dependency "rspec"
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: with_progress
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Marc-Andre Lafortune
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2014-02-04 00:00:00 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: ruby-progressbar
|
16
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ~>
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: "1.4"
|
21
|
+
prerelease: false
|
22
|
+
requirement: *id001
|
23
|
+
type: :runtime
|
24
|
+
- !ruby/object:Gem::Dependency
|
25
|
+
name: backports
|
26
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
27
|
+
requirements:
|
28
|
+
- - ~>
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: "3.5"
|
31
|
+
prerelease: false
|
32
|
+
requirement: *id002
|
33
|
+
type: :runtime
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: bundler
|
36
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: "1.3"
|
41
|
+
prerelease: false
|
42
|
+
requirement: *id003
|
43
|
+
type: :development
|
44
|
+
- !ruby/object:Gem::Dependency
|
45
|
+
name: rake
|
46
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- &id005
|
49
|
+
- ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: "0"
|
52
|
+
prerelease: false
|
53
|
+
requirement: *id004
|
54
|
+
type: :development
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
version_requirements: &id006 !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- *id005
|
60
|
+
prerelease: false
|
61
|
+
requirement: *id006
|
62
|
+
type: :development
|
63
|
+
description: progressbar for enumerables
|
64
|
+
email:
|
65
|
+
- github@marc-andre.ca
|
66
|
+
executables: []
|
67
|
+
|
68
|
+
extensions: []
|
69
|
+
|
70
|
+
extra_rdoc_files: []
|
71
|
+
|
72
|
+
files:
|
73
|
+
- .gitignore
|
74
|
+
- .travis.yml
|
75
|
+
- CHANGELOG.rdoc
|
76
|
+
- Gemfile
|
77
|
+
- LICENSE.txt
|
78
|
+
- README.md
|
79
|
+
- Rakefile
|
80
|
+
- lib/with_progress.rb
|
81
|
+
- lib/with_progress/extensions/enumerable.rb
|
82
|
+
- lib/with_progress/version.rb
|
83
|
+
- spec/manual_spec.rb
|
84
|
+
- spec/with_progress_spec.rb
|
85
|
+
- with_progress.gemspec
|
86
|
+
homepage: http://github.com/marcandre/with_progress
|
87
|
+
licenses:
|
88
|
+
- MIT
|
89
|
+
metadata: {}
|
90
|
+
|
91
|
+
post_install_message:
|
92
|
+
rdoc_options: []
|
93
|
+
|
94
|
+
require_paths:
|
95
|
+
- lib
|
96
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
98
|
+
- *id005
|
99
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- *id005
|
102
|
+
requirements: []
|
103
|
+
|
104
|
+
rubyforge_project:
|
105
|
+
rubygems_version: 2.0.14
|
106
|
+
signing_key:
|
107
|
+
specification_version: 4
|
108
|
+
summary: progressbar for enumerables
|
109
|
+
test_files:
|
110
|
+
- spec/manual_spec.rb
|
111
|
+
- spec/with_progress_spec.rb
|