iostreams 1.8.0 → 1.9.0

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
2
  SHA256:
3
- metadata.gz: b84445b48ac6697a255b5fdacd16783b8573e2cdb75ad395c3b4167ffdd6e01b
4
- data.tar.gz: a37969afc9635fdac60ea45717d64b9bdd8fbb7c6d853a04c0a02cd798274606
3
+ metadata.gz: 410a7bdcec2ee16f130bbb7010bfd2258975253c1bd380c1832f034ae18b2979
4
+ data.tar.gz: 6f8e7bd896166b10a77477a95a0eae88b742a117525d48c10fd23952fa37faa7
5
5
  SHA512:
6
- metadata.gz: 685d6a23dfc176f3abe922fab1879c76572b73dc878864af3e38dfa5824e0eb8c115f855537dcf3c3f2d181b3381512a2c9a20c065beb62cfd91642913c84b30
7
- data.tar.gz: db6e6fcb72c07fe502e64f9ab4d18c79334cde6c1622d1b2ac2a22361ed1f38967adc19bb83959e56fc2039ee595f078c1a92d6277a5b8d39d3802e020df0a1a
6
+ metadata.gz: 85a53eae7c90affdfcd577836d83533d75eff5eb8e880352c6890d4805c219b91e99fc1d936cc72829dbe93d6b8ea55585cc0a2b3a1c8886ab2b261e7c078cb7
7
+ data.tar.gz: 5bd17a2bae394ca10a84f659fe1e0aac8315ab393cfe11e4606b3b0e4ca901d121c2b0aeae91cf6dac0f1939fec039fac21036a5c8382abe382f5d705bf519ad
@@ -79,15 +79,16 @@ module IOStreams
79
79
  # with their options that will be applied when the reader or writer is invoked.
80
80
  def pipeline
81
81
  return streams.dup.freeze if streams
82
- return {}.freeze unless file_name
83
82
 
84
- built_streams = {}
85
- # Encode stream is always first
86
- built_streams[:encode] = options[:encode] if options&.key?(:encode)
83
+ build_pipeline.freeze
84
+ end
87
85
 
88
- opts = options || {}
89
- parse_extensions.each { |stream| built_streams[stream] = opts[stream] || {} }
90
- built_streams.freeze
86
+ # Removes the named stream from the current pipeline.
87
+ # If the stream pipeline has not yet been built it will be built from the file_name if present.
88
+ # Note: Any options must be set _before_ calling this method.
89
+ def remove_from_pipeline(stream_name)
90
+ @streams ||= build_pipeline
91
+ @streams.delete(stream_name.to_sym)
91
92
  end
92
93
 
93
94
  # Returns the tabular format if set, otherwise tries to autodetect the format if the file_name has been set
@@ -106,6 +107,18 @@ module IOStreams
106
107
 
107
108
  private
108
109
 
110
+ def build_pipeline
111
+ return {} unless file_name
112
+
113
+ built_streams = {}
114
+ # Encode stream is always first
115
+ built_streams[:encode] = options[:encode] if options&.key?(:encode)
116
+
117
+ opts = options || {}
118
+ parse_extensions.each { |stream| built_streams[stream] = opts[stream] || {} }
119
+ built_streams
120
+ end
121
+
109
122
  def class_for_stream(type, stream)
110
123
  ext = IOStreams.extensions[stream.nil? ? nil : stream.to_sym] ||
111
124
  raise(ArgumentError, "Unknown Stream type: #{stream.inspect}")
@@ -56,6 +56,14 @@ module IOStreams
56
56
  builder.pipeline
57
57
  end
58
58
 
59
+ # Removes the named stream from the current pipeline.
60
+ # If the stream pipeline has not yet been built it will be built from the file_name if present.
61
+ # Note: Any options must be set _before_ calling this method.
62
+ def remove_from_pipeline(stream_name)
63
+ builder.remove_from_pipeline(stream_name)
64
+ self
65
+ end
66
+
59
67
  # Iterate over a file / stream returning one line at a time.
60
68
  #
61
69
  # Example: Read a line at a time
@@ -1,3 +1,3 @@
1
1
  module IOStreams
2
- VERSION = "1.8.0".freeze
2
+ VERSION = "1.9.0".freeze
3
3
  end
data/test/builder_test.rb CHANGED
@@ -237,6 +237,21 @@ class BuilderTest < Minitest::Test
237
237
  end
238
238
  end
239
239
 
240
+ describe "#remove_from_pipeline" do
241
+ let(:file_name) { "my/path/abc.bz2.pgp" }
242
+ it "removes a named stream from the pipeline" do
243
+ assert_equal({bz2: {}, pgp: {}}, streams.pipeline)
244
+ streams.remove_from_pipeline(:bz2)
245
+ assert_equal({pgp: {}}, streams.pipeline)
246
+ end
247
+ it "removes a named stream from the pipeline with options" do
248
+ streams.option(:pgp, passphrase: "unlock-me")
249
+ assert_equal({bz2: {}, pgp: {passphrase: "unlock-me"}}, streams.pipeline)
250
+ streams.remove_from_pipeline(:bz2)
251
+ assert_equal({pgp: {passphrase: "unlock-me"}}, streams.pipeline)
252
+ end
253
+ end
254
+
240
255
  describe "#execute" do
241
256
  it "directly calls block for an empty stream" do
242
257
  string_io = StringIO.new
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: iostreams
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.0
4
+ version: 1.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Reid Morrison
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-07-22 00:00:00.000000000 Z
11
+ date: 2021-08-17 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: