popro 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +1 -0
- data/lib/popro.rb +13 -0
- data/lib/popro/context.rb +17 -8
- data/lib/popro/indicator.rb +16 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fc8a91c38e9a66e7b5de492fe92f5def2d044fc118a3dfc25ef826ccadc8692c
|
4
|
+
data.tar.gz: 00fc035091657744a3bc7110b91f1cfb49192d07afce1a0866e20745b038c368
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f0c02a15ce252052573de441631e8665f8c2fde13e27162287a01739df908283514f8fa0eb98056e179c2d6ac139aac89bb4a603abd45ae1d9333d960f2de5e4
|
7
|
+
data.tar.gz: 989554d6b7dcf42c8db7a0a1b240b440acf07fd1b965e861486361fe7627fe4c65d37ae8df951daeae37445d689239397613a34f1e6231d11e5addbccdaf586a
|
data/CHANGELOG
CHANGED
data/lib/popro.rb
CHANGED
@@ -7,6 +7,8 @@ module Popro
|
|
7
7
|
|
8
8
|
require_relative 'popro/progress'
|
9
9
|
|
10
|
+
@_is_silenced = false
|
11
|
+
|
10
12
|
def self.new(total = 0, **options, &block)
|
11
13
|
raise ConfigError, 'using :total is not supported in new' if options.key?(:total) && (options[:total] != total)
|
12
14
|
|
@@ -26,6 +28,17 @@ module Popro
|
|
26
28
|
new(0, **options).each_gonna(obj, titler, total, &block).done
|
27
29
|
end
|
28
30
|
|
31
|
+
def self.silenced
|
32
|
+
prev_silenced = @_is_silenced
|
33
|
+
@_is_silenced = true
|
34
|
+
yield
|
35
|
+
@_is_silenced = prev_silenced
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.silenced?
|
39
|
+
@_is_silenced
|
40
|
+
end
|
41
|
+
|
29
42
|
def self.command_line(*_args)
|
30
43
|
raise 'TODO: implement a `ps` style progress indicator for command line'
|
31
44
|
end
|
data/lib/popro/context.rb
CHANGED
@@ -6,11 +6,13 @@ module Popro
|
|
6
6
|
WILL_CHECK_MARKS ||= ' ✔'
|
7
7
|
|
8
8
|
class Context
|
9
|
+
require_relative 'indicator'
|
10
|
+
|
9
11
|
def initialize(progress:, info:, indicator:, step: 1)
|
10
12
|
@progress = progress
|
11
|
-
@indicator = indicator
|
12
13
|
@info = info
|
13
14
|
@step = step
|
15
|
+
@_indicator = indicator
|
14
16
|
end
|
15
17
|
|
16
18
|
def each(obj, total = nil, &block)
|
@@ -39,15 +41,15 @@ module Popro
|
|
39
41
|
raise OutOfSyncError, 'done while not started' unless @info.running?
|
40
42
|
|
41
43
|
@info.finish
|
42
|
-
|
44
|
+
indicator.finish if indicator.respond_to? :finish
|
43
45
|
end
|
44
46
|
|
45
47
|
def formatter(&block)
|
46
|
-
unless @
|
47
|
-
raise ConfigError, "seems formatter is not available for #{@
|
48
|
+
unless @_indicator.respond_to?(:formatter=)
|
49
|
+
raise ConfigError, "seems formatter is not available for #{@_indicator.class}"
|
48
50
|
end
|
49
51
|
|
50
|
-
@
|
52
|
+
@_indicator.formatter = block
|
51
53
|
block
|
52
54
|
end
|
53
55
|
|
@@ -57,20 +59,21 @@ module Popro
|
|
57
59
|
raise TypeError, "amount: expected an integer, got #{amount.class}" unless amount.is_a? Integer
|
58
60
|
|
59
61
|
@info.current += amount unless amount.zero?
|
60
|
-
|
62
|
+
indicator.call(@info, yielded)
|
61
63
|
|
62
64
|
self
|
63
65
|
end
|
64
66
|
|
65
67
|
def gonna(title)
|
66
|
-
@
|
68
|
+
@info.start unless @info.running?
|
69
|
+
indicator.call(@info, title)
|
67
70
|
self
|
68
71
|
end
|
69
72
|
|
70
73
|
def each_gonna(obj, titler, total = nil, &block)
|
71
74
|
_each(obj, total) do |*args|
|
72
75
|
gonna(titler.call(*args))
|
73
|
-
block.call(*args, progress: @info)
|
76
|
+
block.call(*args, progress: @info)
|
74
77
|
end
|
75
78
|
end
|
76
79
|
|
@@ -91,6 +94,12 @@ module Popro
|
|
91
94
|
|
92
95
|
private
|
93
96
|
|
97
|
+
def indicator
|
98
|
+
return Indicator::Null if Popro.silenced?
|
99
|
+
|
100
|
+
@_indicator
|
101
|
+
end
|
102
|
+
|
94
103
|
def _each(obj, total = nil, &block)
|
95
104
|
total = obj.size if total.nil?
|
96
105
|
raise TypeError, "total: expected an integer got #{total.class}" unless total.is_a?(Integer) || total.nil?
|
data/lib/popro/indicator.rb
CHANGED
@@ -1,9 +1,25 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'popro'
|
4
|
+
|
3
5
|
module Popro
|
4
6
|
module Indicator
|
5
7
|
require_relative 'formatter'
|
6
8
|
|
9
|
+
class Null
|
10
|
+
def self.new
|
11
|
+
self
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.initialize
|
15
|
+
self
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.call(*_args); end
|
19
|
+
|
20
|
+
def self.finish; end
|
21
|
+
end
|
22
|
+
|
7
23
|
class Aggregate
|
8
24
|
def initialize(*indicators)
|
9
25
|
@indicators = indicators
|