tqdm 0.3.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: a133210c842f8c1c583898dbf792545371bc69fe
4
- data.tar.gz: 5718d34d881d6cf1b00d7fda4fe5386db526537b
2
+ SHA256:
3
+ metadata.gz: cfebca388873f5a48c60d396d7111a339f488e6b8dd5dd7f178616164bd5bcd0
4
+ data.tar.gz: 79f8f7213f5f63b69f8293bae71163922ed29801975d187cf6a097385ca1b0fe
5
5
  SHA512:
6
- metadata.gz: aa94d7a905513ca26e45d712db7b63bf1ddc503915e99f728bda5eef4475b916a99bbf969fae97511bc656d8cfd173664cdd16f9ef95b4a8ecf5fcd0263497ae
7
- data.tar.gz: 491b60be374b5fa7c4ff2fa473f4359c6aa7130942197ea3e43b74c4e301d2f0ed348ffcc271c50b29d0a8334f81a60bc1c04ffa6ce14d4cabc22e1b4bf40ca9
6
+ metadata.gz: 1e9f372b270f9c914e8d3f5206105a702c25373d2f7a56aec7488468f2c593dfc3077ffa4b0d0cd19ce73f99c3d15b39728a82ce3157150277c8a50268624fc3
7
+ data.tar.gz: 80ebc6f10d9f2cad69ee96f210cd8bb8c48667fb537c2d2616e679e0c34cd9afc867df5787e30cf191ebbce7e2ce477d0202ebba912db6a56113dccecca67ad8
@@ -0,0 +1,38 @@
1
+ # This workflow uses actions that are not certified by GitHub.
2
+ # They are provided by a third-party and are governed by
3
+ # separate terms of service, privacy policy, and support
4
+ # documentation.
5
+ # This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
6
+ # For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
7
+
8
+ name: Ruby-CI
9
+
10
+ on:
11
+ push:
12
+ branches: [ "master" ]
13
+ pull_request:
14
+ branches: [ "master" ]
15
+
16
+ permissions:
17
+ contents: read
18
+
19
+ jobs:
20
+ test:
21
+
22
+ runs-on: ubuntu-latest
23
+ strategy:
24
+ matrix:
25
+ ruby-version: ['1.9', '2.0', '2.6', '2.7', '3.0', '3.1']
26
+
27
+ steps:
28
+ - uses: actions/checkout@v3
29
+ - name: Set up Ruby
30
+ # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
31
+ # change this to (see https://github.com/ruby/setup-ruby#versioning):
32
+ # uses: ruby/setup-ruby@v1
33
+ uses: ruby/setup-ruby@ee2113536afb7f793eed4ce60e8d3b26db912da4 # v1.127.0
34
+ with:
35
+ ruby-version: ${{ matrix.ruby-version }}
36
+ bundler-cache: true # runs 'bundle install' and caches installed gems automatically
37
+ - name: Run tests
38
+ run: bundle exec rake spec
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2016 Theodore Pak
1
+ Copyright (c) 2022 Theodore Pak
2
2
 
3
3
  MIT License
4
4
 
data/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  # tqdm-ruby
2
- [![Build Status](https://travis-ci.org/powerpak/tqdm-ruby.svg?branch=master)](https://travis-ci.org/powerpak/tqdm-ruby) [![Gem Version](https://badge.fury.io/rb/tqdm.svg)](https://badge.fury.io/rb/tqdm)
2
+ [![Build Status](https://github.com/powerpak/tqdm-ruby/actions/workflows/ruby-ci.yml/badge.svg?branch=master&event=push)](https://github.com/powerpak/tqdm-ruby/actions/workflows/ruby-ci.yml?query=event%3Apush+branch%3Amaster) [![Gem Version](https://badge.fury.io/rb/tqdm.svg?version=0.4.0)](https://badge.fury.io/rb/tqdm)
3
3
 
4
4
  tqdm-ruby allows you to add a progress indicator to your loops with minimal effort.
5
5
 
@@ -29,7 +29,7 @@ It works equally well from within irb, [pry](http://pryrepl.org/), and [iRuby no
29
29
 
30
30
  Install it globally from [Rubygems](https://rubygems.org/gems/tqdm):
31
31
 
32
- $ gem install tqdm # (might need sudo on OS X)
32
+ $ gem install tqdm # (might need sudo for a system ruby)
33
33
 
34
34
  *or* add this line to your application's Gemfile:
35
35
 
@@ -1,6 +1,11 @@
1
1
  require 'tqdm/printer'
2
2
 
3
+ CLONE_UNFROZEN_SUPPORTED = RUBY_VERSION.split('.')[0..1].join('.').to_f >= 2.4
4
+
3
5
  module Tqdm
6
+
7
+ class DecoratorError < StandardError
8
+ end
4
9
 
5
10
  # Decorates the #each method of an `Enumerable` by wrapping it so that each
6
11
  # iteration produces a pretty progress bar printed to the console or a file handle.
@@ -44,6 +49,7 @@ module Tqdm
44
49
  @min_iterations = options[:min_iters] || 1
45
50
  @min_interval = options[:min_interval] || 0.5
46
51
  @leave = options[:leave] || false
52
+ @force_refreeze = false
47
53
  end
48
54
 
49
55
  # Starts the textual progress bar.
@@ -87,6 +93,7 @@ module Tqdm
87
93
  # progress bar.
88
94
  def enhance
89
95
  decorate_enumerable_each
96
+ enhanced.freeze if @force_refreeze
90
97
  enhanced
91
98
  end
92
99
 
@@ -96,8 +103,8 @@ module Tqdm
96
103
  tqdm = self
97
104
  enhanced.define_singleton_method(:each) do |*args, &block|
98
105
  tqdm.start!
99
- result = super(*args) do |item|
100
- block.call item if block
106
+ result = super(*args) do |*items|
107
+ block.call *items if block
101
108
  tqdm.increment!
102
109
  end
103
110
  tqdm.finish!
@@ -106,7 +113,27 @@ module Tqdm
106
113
  end
107
114
 
108
115
  def enhanced
109
- @enhanced ||= enumerable.clone
116
+ @enhanced ||= enumerable_unfrozen
117
+ end
118
+
119
+ # Uses progressively more invasive techniques to return an unfrozen copy of @enumerable
120
+ def enumerable_unfrozen
121
+ to_unfreeze = CLONE_UNFROZEN_SUPPORTED ? enumerable.clone(freeze: false) : enumerable.clone
122
+ return to_unfreeze unless to_unfreeze.frozen?
123
+ to_unfreeze = to_unfreeze.dup
124
+ return to_unfreeze unless to_unfreeze.frozen?
125
+
126
+ # Significantly, for some classes like Sequel::Dataset, both #clone and #dup re-freeze
127
+ # the object before returning it, so we have to drop back to Object#clone to avoid this
128
+ @force_refreeze = true
129
+ if CLONE_UNFROZEN_SUPPORTED
130
+ to_unfreeze = Object.instance_method(:clone).bind(enumerable).call(freeze: false)
131
+ end
132
+ if Object.instance_method(:frozen?).bind(to_unfreeze).call
133
+ raise DecoratorError.new("could not create an unfrozen clone")
134
+ end
135
+
136
+ to_unfreeze
110
137
  end
111
138
 
112
139
  def total!
data/lib/tqdm/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  module Tqdm
2
2
  # The version of this module and gem by the same name.
3
- VERSION = "0.3.0"
3
+ VERSION = "0.4.1"
4
4
  end
data/spec/sequel_spec.rb CHANGED
@@ -38,6 +38,18 @@ describe 'When enumerating over a Sequel dataset' do
38
38
  "\r " \
39
39
  "\r"
40
40
  end
41
+
42
+ it 'returns a re-frozen object' do
43
+ enhanced = nil
44
+ with_stderr { enhanced = timecop_loop(database[:items]) }
45
+ expect(enhanced.frozen?).to be_truthy
46
+ end
47
+
48
+ it 'returns an object inheriting from Sequel::Dataset' do
49
+ enhanced = nil
50
+ with_stderr { enhanced = timecop_loop(database[:items]) }
51
+ expect(enhanced).to be_kind_of(Sequel::Dataset)
52
+ end
41
53
  end
42
54
 
43
55
  context 'with leave: true' do
data/tqdm.gemspec CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_development_dependency "bundler", "~> 1.3"
21
+ spec.add_development_dependency "bundler"
22
22
  spec.add_development_dependency "rake"
23
23
  spec.add_development_dependency "sequel"
24
24
  spec.add_development_dependency "sqlite3"
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tqdm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Theodore Pak
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-21 00:00:00.000000000 Z
11
+ date: 2023-01-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '1.3'
19
+ version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '1.3'
26
+ version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -102,9 +102,9 @@ executables: []
102
102
  extensions: []
103
103
  extra_rdoc_files: []
104
104
  files:
105
+ - ".github/workflows/ruby-ci.yml"
105
106
  - ".gitignore"
106
107
  - ".rspec"
107
- - ".travis.yml"
108
108
  - ".yardopts"
109
109
  - Gemfile
110
110
  - LICENSE.txt
@@ -140,8 +140,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
140
140
  - !ruby/object:Gem::Version
141
141
  version: '0'
142
142
  requirements: []
143
- rubyforge_project:
144
- rubygems_version: 2.2.5
143
+ rubygems_version: 3.1.6
145
144
  signing_key:
146
145
  specification_version: 4
147
146
  summary: Enhances Enumerables to show progress while iterating.
data/.travis.yml DELETED
@@ -1,8 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - "1.9.2"
4
- - "1.9.3"
5
- - "2.0.0"
6
- - "2.1.8"
7
- - "2.2.4"
8
- - rbx