trick_bag 0.68.0 → 0.69.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 59ec06de448c4ccb3f3cd3966fcdc855cb602ac5
4
- data.tar.gz: 67da903f678ed62aae6d7e0ba4d84441fe6a837a
2
+ SHA256:
3
+ metadata.gz: 8c964fe06a56296126af07267b11108fcb6e8722b73a7faece5a1e9dee83081e
4
+ data.tar.gz: abac32f4c508b3d8c1eb05ef53561f2d6e173d680310fc4adfbe5f6cf5a303dd
5
5
  SHA512:
6
- metadata.gz: b8919fe6998b064c515dd6440474327691558c72c0755e93337d1e6c066fce99a6436610fe15651a71e6964ceb94b1daf785f225eaf3c2f38cb7dcb45f4c6906
7
- data.tar.gz: a488a53c4369a98e6adf563e07b8f60d758726f7299aed2e6da47b6366caed364e4fbc57d7c059d9db499a09c36b4338aa71e8247852ac04fcc742116e364dcb
6
+ metadata.gz: 40d8c1188804504e01e339f13287b0803461ee425fce82e55221c74576e1ef4eadf08a5c0049f5924ea820ca11a1039c2adf98d3eed14968dbceb33904026683
7
+ data.tar.gz: d675e3eb74bb6f28e8ea329a47992c2803ff526ad54eab9ffbd0344d7b12c0b5d6d7ac88c1d1ec603f4c844db9cc984a8ff376e217b5581627a2798e3e750e8f
@@ -1,3 +1,8 @@
1
+ ## v0.69.0
2
+
3
+ In BufferedEnumerable, rename create_with_lambdas to create_with_callables. Create alias so old name still works.
4
+
5
+
1
6
  ## v0.68.0
2
7
 
3
8
  * Add Filesystem.running_as_script?
@@ -8,10 +8,10 @@ module Enumerables
8
8
  # fetches them in chunks.
9
9
  #
10
10
  # This class knows nothing about how to fetch anything; that behavior is provided
11
- # by either subclassing this class, or calling .create_with_lambdas and passing
12
- # a lambda that knows how to do that.
11
+ # by either subclassing this class, or calling .create_with_callables and passing
12
+ # a callable that knows how to do that.
13
13
  #
14
- # Also supported is an optional fetch notification, a method or lambda that will
14
+ # Also supported is an optional fetch notification, a method or callable that will
15
15
  # be called whenever a fetch is done. This can be useful to update counters,
16
16
  # provide user feedback (e.g. a progress bar), etc.
17
17
  #
@@ -19,8 +19,8 @@ module Enumerables
19
19
  # one immediately after another, and the responses can be collected as a group,
20
20
  # for improved performance.
21
21
  #
22
- # The fetch method and fetcher lambda modify the instance's data array directly,
23
- # to avoid the need to allow the lambda to modify the data array reference,
22
+ # The fetch method and fetcher callable modify the instance's data array directly,
23
+ # to avoid the need to allow the callable to modify the data array reference,
24
24
  # needlessly copying arrays,
25
25
  # and to eliminate the need for garbage collecting many array objects
26
26
  # (though the latter is rarely important).
@@ -37,20 +37,25 @@ class BufferedEnumerable
37
37
  attr_access :public, :private, :chunk_count, :fetch_count, :yield_count
38
38
 
39
39
 
40
- # Creates an instance with lambdas for fetch and fetch notify behaviors.
40
+ # Creates an instance with callables for fetch and fetch notify behaviors.
41
+ # Callables are usually lambdas but can be any object responding to the method name `call`.
41
42
  # @param chunk_size the maximum number of objects to be buffered
42
- # @param fetcher lambda to be called to fetch to fill the buffer
43
- # @param fetch_notifier lambda to be called to when a fetch is done
44
- def self.create_with_lambdas(chunk_size, fetcher, fetch_notifier = nil)
43
+ # @param fetcher callable to be called to fetch to fill the buffer
44
+ # @param fetch_notifier callable to be called to when a fetch is done
45
+ def self.create_with_callables(chunk_size, fetcher, fetch_notifier = nil)
45
46
  instance = self.new(chunk_size)
46
47
  instance.fetcher = fetcher
47
48
  instance.fetch_notifier = fetch_notifier
48
49
  instance
49
50
  end
51
+ class << self
52
+ alias_method :create_with_lambdas, :create_with_callables
53
+ end
54
+
50
55
 
51
- # @param fetcher lambda to be called to fetch to fill the buffer
56
+ # @param fetcher callable to be called to fetch to fill the buffer
52
57
  # @param chunk_size the maximum number of objects to be buffered
53
- # @param fetch_notifier lambda to be called to when a fetch is done
58
+ # @param fetch_notifier callable to be called to when a fetch is done
54
59
  # in case the caller wants to receive notification, update counters, etc.
55
60
  # It's passed the array of objects just fetched, whose size may be
56
61
  # less than chunk size.
@@ -63,14 +68,14 @@ class BufferedEnumerable
63
68
  end
64
69
 
65
70
 
66
- # Unless you use self.create_with_lambdas to create your instance,
71
+ # Unless you use self.create_with_callables to create your instance,
67
72
  # you'll need to override this method in your subclass.
68
73
  def fetch
69
74
  fetcher.(data, chunk_size) if fetcher
70
75
  end
71
76
 
72
77
 
73
- # Unless you use self.create_with_lambdas to create your instance,
78
+ # Unless you use self.create_with_callables to create your instance,
74
79
  # you'll need to override this method in your subclass.
75
80
  def fetch_notify
76
81
  fetch_notifier.(data) if fetch_notifier
@@ -6,16 +6,14 @@ module Filesystem
6
6
  # @return true if the passed file is being run as a script, else false
7
7
  # @param __file__ - !!! __FILE__ must be passed as the __file__ argument for this to work correctly !!!
8
8
  #
9
+ # When the file's behavior needs to differ when running as a script and _not_ running as a script,
10
+ # this method can be called to report which of the two states it is.
11
+ #
9
12
  # Sometimes we want to see if a given file is being run as a script, as opposed to loaded
10
13
  # by other Ruby code. For example, the script at https://github.com/keithrbennett/macwifi/blob/master/bin/mac-wifi
11
14
  # is normally run as a script (either by running the file directly, or by running the executable's
12
15
  # binstub installed by the gem), but it can also be loaded so that the model can be used by custom code.
13
- #
14
- # When the file's behavior needs to differ when running as a script and _not_ running as a script,
15
- # this method can be called to report which of the two states it is.
16
- #
17
- # An example of differing behavior is also in the case of `mac-wifi`. When run as a script,
18
- # it parses the command line and executes a task, sending text to stdout.
16
+ # When run as a script, it parses the command line and executes a task, sending text to stdout.
19
17
  def running_as_script?(__file__)
20
18
 
21
19
  # Here is some sample state, when running a file as a gem executable:
@@ -36,7 +34,8 @@ module Filesystem
36
34
  basename = File.basename($0)
37
35
  gem_paths.any? do |path|
38
36
  ($0 == File.join(path, 'bin', basename)) \
39
- && (path == File.expand_path(File.join(__file__, '..', '..', '..', '..')))
37
+ && \
38
+ (path == File.expand_path(File.join(__file__, '..', '..', '..', '..')))
40
39
  end
41
40
  end
42
41
  end
@@ -4,28 +4,28 @@ module TrickBag
4
4
  module Io
5
5
  module TempFiles
6
6
 
7
- module_function
7
+ module_function
8
8
 
9
- # For the easy creation and deletion of a temp file populated with text,
10
- # wrapped around the code block you provide.
11
- #
12
- # @param text the text to write to the temporary file
13
- # @param file_prefix optional prefix for the temporary file's name
14
- # @yield filespec of the temporary file
15
- def file_containing(text, file_prefix = '')
16
- raise "This method must be called with a code block." unless block_given?
9
+ # For the easy creation and deletion of a temp file populated with text,
10
+ # wrapped around the code block you provide.
11
+ #
12
+ # @param text the text to write to the temporary file
13
+ # @param file_prefix optional prefix for the temporary file's name
14
+ # @yield filespec of the temporary file
15
+ def file_containing(text, file_prefix = '')
16
+ raise "This method must be called with a code block." unless block_given?
17
17
 
18
- filespec = nil
19
- begin
20
- Tempfile.open(file_prefix) do |file|
21
- file << text
22
- filespec = file.path
23
- end
24
- yield(filespec)
25
- ensure
26
- File.delete filespec if filespec && File.exist?(filespec)
18
+ filespec = nil
19
+ begin
20
+ Tempfile.open(file_prefix) do |file|
21
+ file << text
22
+ filespec = file.path
27
23
  end
24
+ yield(filespec)
25
+ ensure
26
+ File.delete(filespec) if filespec && File.exist?(filespec)
28
27
  end
29
28
  end
30
29
  end
31
30
  end
31
+ end
@@ -1,8 +1,6 @@
1
1
  module TrickBag
2
2
  module Io
3
3
 
4
- # Provides an updatable and customizable status/information line in a terminal,
5
- # typically used to display progress.
6
4
  # Updates the terminal line with text, erasing the original content and displaying at the same place.
7
5
  # Uses ANSI escape sequences for cursor positioning and clearing
8
6
  # (see http://www.oldlinux.org/Linux.old/Ref-docs/ASCII/ANSI%20Escape%20Sequences.htm).
@@ -116,7 +116,9 @@ class SshOutputReader
116
116
  end
117
117
 
118
118
 
119
-
119
+ # This is an eample of use of the class that will be run if the file is run explicitly
120
+ # i.e.: ruby ssh_output_reader.rb
121
+ # This should be moved somewhere else.
120
122
  if $0 == __FILE__
121
123
 
122
124
  Thread.abort_on_exception = true
@@ -147,6 +149,8 @@ echo 3
147
149
  sleep 1
148
150
  echo 4'
149
151
 
152
+ # TODO: Clean this up!
153
+
150
154
  # reader = SshOutputReader.new('localhost', command)
151
155
  # reader.run
152
156
  # puts "All reader stdout:\n" + reader.all_stdout
@@ -1,3 +1,3 @@
1
1
  module TrickBag
2
- VERSION = '0.68.0'
2
+ VERSION = '0.69.0'
3
3
  end
@@ -6,7 +6,7 @@ module Enumerables
6
6
 
7
7
  describe BufferedEnumerable do
8
8
 
9
- context 'when created with lambdas' do
9
+ context 'when created with callables' do
10
10
  # Returns an object that returns chunks of incrementing integers.
11
11
  let(:fetcher) do
12
12
  object = 0
@@ -27,15 +27,15 @@ module Enumerables
27
27
  object_count += fetched_objects.size
28
28
  end
29
29
 
30
- e = BufferedEnumerable.create_with_lambdas(4, fetcher, fetch_notifier).to_enum
30
+ e = BufferedEnumerable.create_with_callables(4, fetcher, fetch_notifier).to_enum
31
31
  (1..10).each { |n| expect(e.next).to eq(n) }
32
32
  expect(chunk_fetch_calls).to eq(3)
33
33
  expect(object_count).to eq(12)
34
34
  end
35
35
 
36
- specify 'create_with_lambdas can be called without specifying a fetch_notifier' do
36
+ specify 'create_with_callables can be called without specifying a fetch_notifier' do
37
37
  be = nil
38
- f1 = -> { be = BufferedEnumerable.create_with_lambdas(4, fetcher).to_enum }
38
+ f1 = -> { be = BufferedEnumerable.create_with_callables(4, fetcher).to_enum }
39
39
  expect(f1).not_to raise_error
40
40
  f2 = -> { (1..10).each { be.next } }
41
41
  expect(f2).not_to raise_error
@@ -43,6 +43,12 @@ module Enumerables
43
43
  end
44
44
 
45
45
 
46
+ specify 'create with old method name create_with_lambdas still works' do
47
+ buffered_enumerable = BufferedEnumerable.create_with_lambdas(4, ->() {}, ->() {})
48
+ expect(buffered_enumerable.class).to eq(BufferedEnumerable)
49
+ end
50
+
51
+
46
52
  context "when instantiating a subclass" do
47
53
  specify 'the values and number of fetches are correct' do
48
54
  create_test_class = ->() do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trick_bag
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.68.0
4
+ version: 0.69.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Keith Bennett
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-10-01 00:00:00.000000000 Z
11
+ date: 2018-07-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: os
@@ -224,7 +224,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
224
224
  version: '0'
225
225
  requirements: []
226
226
  rubyforge_project:
227
- rubygems_version: 2.6.13
227
+ rubygems_version: 2.7.6
228
228
  signing_key:
229
229
  specification_version: 4
230
230
  summary: Miscellaneous general useful tools.