iostreams 1.0.0 → 1.1.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
2
  SHA256:
3
- metadata.gz: e81d84bc2bb265b09acc66d39fa3ebc168d045127cf9942ce49cb06c5da369f2
4
- data.tar.gz: 534e1bf05113578b1848fe196981b21c516115c783d778bb31ec78b0bc60b271
3
+ metadata.gz: 1a047f1f33b360bf1aa4f028da098e5d2364e4e4ebc4f4c603c445e6f43f99d8
4
+ data.tar.gz: 42e7095dcdb7707ec774f6d5efe104418fcb632af97d2978e736ddd3ec7c72ae
5
5
  SHA512:
6
- metadata.gz: 7a9bdf64f5142ab31c6e3f1f620d6e619041c7b9802928fd2b9c2508b9c90b95e943188299632c2407660594a0aeecbe3b5fc61a7bee80703701cfdf2827d906
7
- data.tar.gz: d9584118b6bb8088c2e1e54f60fc2370213d693b1130e0e104c5a6cfcc4027b776e736f39e71393e14c0510ab1353d76398fad9ff44ec32479d17bbb5f45c86d
6
+ metadata.gz: ef9b14f94069a48f81cfb52960a115f0bfb83bcebde57850002d52148e2cb495a0eed9a9f1a6505e1210dd259cc1ab8555e36cb7e9769410a48ca11daa4c4b9c
7
+ data.tar.gz: b8b0bc72a97bbb7174c32e3d852ce171e6443d246950f788016ed4309e539d644703765fd2767c36ea4df7b8218d7b14b84c94a8630d5214a1bc60b0f4659472
@@ -233,6 +233,24 @@ module IOStreams
233
233
  @root_paths.dup
234
234
  end
235
235
 
236
+ # Set the temporary path to use when creating local temp files.
237
+ def self.temp_dir=(temp_dir)
238
+ temp_dir = File.expand_path(temp_dir)
239
+ FileUtils.mkdir_p(temp_dir) unless ::File.exist?(temp_dir)
240
+
241
+ @temp_dir = temp_dir
242
+ end
243
+
244
+ # Returns the temporary path used when creating local temp files.
245
+ #
246
+ # Default:
247
+ # ENV['TMPDIR'], or ENV['TMP'], or ENV['TEMP'], or `Etc.systmpdir`, or '/tmp', otherwise '.'
248
+ def self.temp_dir
249
+ @temp_dir ||= Dir.tmpdir
250
+ end
251
+
252
+ @temp_dir = nil
253
+
236
254
  # Register a file extension and the reader and writer streaming classes
237
255
  #
238
256
  # Example:
@@ -19,7 +19,7 @@ module IOStreams
19
19
  def initialize(path, pattern, case_sensitive: false, hidden: false)
20
20
  extract_optimized_path(path, pattern)
21
21
 
22
- @flags = ::File::FNM_EXTGLOB
22
+ @flags = ::File::FNM_EXTGLOB | ::File::FNM_PATHNAME
23
23
  @flags |= ::File::FNM_CASEFOLD unless case_sensitive
24
24
  @flags |= ::File::FNM_DOTMATCH if hidden
25
25
  end
@@ -71,7 +71,7 @@ module IOStreams
71
71
  # end
72
72
  #
73
73
  # # When using the sftp executable use an identity file instead of a password to authenticate:
74
- # IOStreams.path("sftp://test.com/path/file_name.csv", username: "jack", IdentityFile: "~/.ssh/private_key").reader do |io|
74
+ # IOStreams.path("sftp://test.com/path/file_name.csv", username: "jack", ssh_options: {IdentityFile: "~/.ssh/private_key"}).reader do |io|
75
75
  # puts io.read
76
76
  # end
77
77
  def initialize(url, username: nil, password: nil, ssh_options: {})
@@ -48,7 +48,6 @@ module IOStreams
48
48
  # Return the options already set for either a stream or option.
49
49
  def setting(stream)
50
50
  builder.setting(stream)
51
- self
52
51
  end
53
52
 
54
53
  # Returns [Hash<Symbol:Hash>] the pipeline of streams
@@ -1,5 +1,8 @@
1
+ require 'uri'
1
2
  module IOStreams
2
3
  module Utils
4
+ MAX_TEMP_FILE_NAME_ATTEMPTS = 5
5
+
3
6
  # Lazy load dependent gem so that it remains a soft dependency.
4
7
  def self.load_soft_dependency(gem_name, stream_type, require_name = gem_name)
5
8
  require require_name
@@ -23,7 +26,7 @@ module IOStreams
23
26
  # File is deleted upon completion if present.
24
27
  def self.temp_file_name(basename, extension = '')
25
28
  result = nil
26
- ::Dir::Tmpname.create([basename, extension]) do |tmpname|
29
+ ::Dir::Tmpname.create([basename, extension], IOStreams.temp_dir, max_try: MAX_TEMP_FILE_NAME_ATTEMPTS) do |tmpname|
27
30
  begin
28
31
  result = yield(tmpname)
29
32
  ensure
@@ -1,3 +1,3 @@
1
1
  module IOStreams
2
- VERSION = "1.0.0".freeze
2
+ VERSION = "1.1.0".freeze
3
3
  end
@@ -48,7 +48,7 @@ module IOStreams
48
48
  # The input stream from the first file found in the zip file is passed
49
49
  # to the supplied block
50
50
  def self.file(file_name, entry_file_name: nil, &block)
51
- Utils.load_soft_dependency('rubyzip', 'Read Zip', 'zip') unless defined?(::Zip)
51
+ Utils.load_soft_dependency('rubyzip v1.x', 'Read Zip', 'zip') unless defined?(::Zip)
52
52
 
53
53
  ::Zip::File.open(file_name) do |zip_file|
54
54
  if entry_file_name
@@ -11,11 +11,11 @@ module Paths
11
11
  expected_path: "/path/work/a/b/c",
12
12
  expected_pattern: "**/*",
13
13
  recursive: true,
14
- matches: %w[/path/work/a/b/c/any/file /path/work/a/b/c/other/file /path/work/a/b/c/sub/.name],
15
- not_matches: %w[/path/work/a/b/c/.profile]
14
+ matches: %w[/path/work/a/b/c/any/file /path/work/a/b/c/other/file],
15
+ not_matches: %w[/path/work/a/b/c/.profile /path/work/a/b/c/sub/.name]
16
16
  },
17
- {path: "/path/work", pattern: "a/b/c?/**/*", expected_path: "/path/work/a/b", expected_pattern: "c?/**/*", recursive: true},
18
- {path: "/path/work", pattern: "**/*", expected_path: "/path/work", expected_pattern: "**/*", recursive: true},
17
+ {path: "/path/work", pattern: "a/b/c?/**", expected_path: "/path/work/a/b", expected_pattern: "c?/**", recursive: true},
18
+ {path: "/path/work", pattern: "**", expected_path: "/path/work", expected_pattern: "**", recursive: true},
19
19
  # Case-insensitive exists that returns the actual file name.
20
20
  {path: "/path/work", pattern: "a/b/file.txt", expected_path: "/path/work/a/b/file.txt", expected_pattern: nil, recursive: false},
21
21
  {
@@ -25,7 +25,17 @@ module Paths
25
25
  expected_pattern: "file*{zip,gz}",
26
26
  recursive: false,
27
27
  matches: %w[/path/work/a/b/file.GZ /path/work/a/b/FILE.ZIP /path/work/a/b/file123.zIp],
28
- not_matches: %w[/path/work/a/b/.profile /path/work/a/b/filter.zip],
28
+ not_matches: %w[/path/work/a/b/.profile /path/work/a/b/filter.zip /path/work/a/b/outgoing/filter.zip],
29
+ case_sensitive: false
30
+ },
31
+ {
32
+ path: "/path/work",
33
+ pattern: "a/b/*",
34
+ expected_path: "/path/work/a/b",
35
+ expected_pattern: "*",
36
+ recursive: false,
37
+ matches: %w[/path/work/a/b/file.GZ /path/work/a/b/FILE.ZIP /path/work/a/b/file123.zIp],
38
+ not_matches: %w[/path/work/a/b/.profile /path/work/a/b/my/filter.zip /path/work/a/b/outgoing/filter.zip],
29
39
  case_sensitive: false
30
40
  },
31
41
  {
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.0.0
4
+ version: 1.1.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: 2020-01-14 00:00:00.000000000 Z
11
+ date: 2020-02-24 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email:
@@ -130,7 +130,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
130
130
  - !ruby/object:Gem::Version
131
131
  version: '0'
132
132
  requirements: []
133
- rubygems_version: 3.1.2
133
+ rubygems_version: 3.0.6
134
134
  signing_key:
135
135
  specification_version: 4
136
136
  summary: Input and Output streaming for Ruby.