popro 0.2.2 → 0.2.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a790befdf497a693172bb0faf40561c1d7fd6e287a3b5c379f7ddd9496f33509
4
- data.tar.gz: a015de37abef0c5769a5d786182319fb891e874124daa5503a7feb9b411438fe
3
+ metadata.gz: fc8a91c38e9a66e7b5de492fe92f5def2d044fc118a3dfc25ef826ccadc8692c
4
+ data.tar.gz: 00fc035091657744a3bc7110b91f1cfb49192d07afce1a0866e20745b038c368
5
5
  SHA512:
6
- metadata.gz: 0a2b3c066fe0a666537e40a2d63b81442e463c4b421a29d67722ad364453695fe17ea247a66c8d2e695e389b1482b56788dc03efff8836821a63f61d0592a5dd
7
- data.tar.gz: 87151aae4f7c3ac0650960e5fdf646d4a373742dec759e3872fb8ea3be96c5b64b585401e6b6897c57ed7c86ed23987f1d33f426ffafbabf8e50558348046d3f
6
+ metadata.gz: f0c02a15ce252052573de441631e8665f8c2fde13e27162287a01739df908283514f8fa0eb98056e179c2d6ac139aac89bb4a603abd45ae1d9333d960f2de5e4
7
+ data.tar.gz: 989554d6b7dcf42c8db7a0a1b240b440acf07fd1b965e861486361fe7627fe4c65d37ae8df951daeae37445d689239397613a34f1e6231d11e5addbccdaf586a
data/CHANGELOG CHANGED
@@ -1,3 +1,4 @@
1
+ 0.2.3 add support for `Popro.silenced`
1
2
  0.2.2 add gonna and each_gonna, add Callback Indicator
2
3
  0.2.1 add support for estimation and re-use of default indicator with added concatted formatters
3
4
  0.2.0 various fixes and added unit tests
@@ -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
@@ -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
- @indicator.finish if @indicator.respond_to? :finish
44
+ indicator.finish if indicator.respond_to? :finish
43
45
  end
44
46
 
45
47
  def formatter(&block)
46
- unless @indicator.respond_to?(:formatter=)
47
- raise ConfigError, "seems formatter is not available for #{@indicator.class}"
48
+ unless @_indicator.respond_to?(:formatter=)
49
+ raise ConfigError, "seems formatter is not available for #{@_indicator.class}"
48
50
  end
49
51
 
50
- @indicator.formatter = block
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
- @indicator.call(@info, yielded)
62
+ indicator.call(@info, yielded)
61
63
 
62
64
  self
63
65
  end
64
66
 
65
67
  def gonna(title)
66
- @indicator.call(@info, title)
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) if block_given?
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?
@@ -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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: popro
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - MikeSmithEU