with_progress 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.travis.yml ADDED
@@ -0,0 +1,12 @@
1
+ ---
2
+ language: ruby
3
+ rvm:
4
+ - "1.8.7"
5
+ - "1.9.2"
6
+ - "1.9.3"
7
+ - "2.0.0"
8
+ - "2.1.0"
9
+ - ruby-head
10
+ - jruby-18mode
11
+ - jruby-19mode
12
+ - rbx-2.1.1
data/CHANGELOG.rdoc ADDED
@@ -0,0 +1,5 @@
1
+ = with_progress --- History
2
+
3
+ == Version 1.0 - February 3rd, 2014
4
+
5
+ === Initial release.
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in with_progress.gemspec
4
+ gemspec
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,6 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -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
@@ -0,0 +1,3 @@
1
+ module WithProgress
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,9 @@
1
+ require 'with_progress/version'
2
+ require 'with_progress/extensions/enumerable'
3
+ require 'ruby-progressbar'
4
+ require 'backports/2.0.0/range/size'
5
+
6
+ module WithProgress
7
+ DEFAULTS = {:format => ENV['RUBY_WITH_PROGRESS'] || '%t: |%B| %E'}
8
+ end
9
+
@@ -0,0 +1,10 @@
1
+ require 'with_progress'
2
+
3
+ describe "Progress" do
4
+ it "looks good" do
5
+ (0...10).with_progress do
6
+ sleep 0.5
7
+ end
8
+ puts "Did it look good?"
9
+ end
10
+ end
@@ -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