iostreams 0.20.0 → 0.20.1
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 +4 -4
- data/lib/io_streams/io_streams.rb +43 -24
- data/lib/io_streams/version.rb +1 -1
- data/test/path_test.rb +14 -14
- data/test/test_helper.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d2c3b941a898cf14f2e8d5ac430f55efc602126f0d2e339014cb3de97d7c9233
|
4
|
+
data.tar.gz: e5745a12f24746ecf624627ac45e900251b0c3b83b109d7f18c04ffaf4efeba5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ae879c20c587da2b9a2c5ae36a0488346b49f11470bd812640d6ccda161434221b98cdb65c5d7cc2988492621822a4e301665033e94207f90b323299b2e0fc24
|
7
|
+
data.tar.gz: a325782b46feeaf314a94f758be89d02b006fabfe824c91b2ac17309841980cab4cb9129318040426d9d6582bff6dd7345bc40f9234b0cd2e89c0d5555948335
|
@@ -425,50 +425,69 @@ module IOStreams
|
|
425
425
|
end
|
426
426
|
end
|
427
427
|
|
428
|
-
#
|
428
|
+
# Returns [Path] instance for the supplied complete path with optional scheme.
|
429
429
|
#
|
430
430
|
# Example:
|
431
|
-
# IOStreams.path(
|
432
|
-
# # => "/
|
431
|
+
# IOStreams.path("/usr", "local", "sample")
|
432
|
+
# # => #<IOStreams::File::Path:0x00007fec66e59b60 @path="/usr/local/sample">
|
433
433
|
#
|
434
|
-
# IOStreams.path(
|
435
|
-
# # => "/
|
434
|
+
# IOStreams.path("/usr", "local", "sample").to_s
|
435
|
+
# # => "/usr/local/sample"
|
436
436
|
#
|
437
|
-
# IOStreams.path(
|
438
|
-
# # => "/
|
437
|
+
# IOStreams.path("s3://mybucket/path/file.xls")
|
438
|
+
# # => #<IOStreams::S3::Path:0x00007fec66e3a288, @path="s3://mybucket/path/file.xls">
|
439
439
|
#
|
440
|
-
# IOStreams.path(
|
441
|
-
# # => "/
|
440
|
+
# IOStreams.path("s3://mybucket/path/file.xls").to_s
|
441
|
+
# # => "s3://mybucket/path/file.xls"
|
442
442
|
#
|
443
|
-
#
|
444
|
-
#
|
445
|
-
#
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
# When using a full path, without needing the root prefixed.
|
451
|
-
def self.full_path(*elements)
|
443
|
+
# IOStreams.path("file.xls")
|
444
|
+
# # => #<IOStreams::File::Path:0x00007fec6be6aaf0 @path="file.xls">
|
445
|
+
#
|
446
|
+
# IOStreams.path("files", "file.xls").to_s
|
447
|
+
# # => "files/file.xls"
|
448
|
+
def self.path(*elements)
|
452
449
|
path = ::File.join(*elements)
|
453
450
|
uri = URI.parse(path)
|
454
451
|
IOStreams.scheme(uri.scheme).path_class.new(path)
|
455
452
|
end
|
456
453
|
|
454
|
+
# Join the supplied path elements to a root path.
|
455
|
+
#
|
456
|
+
# Example:
|
457
|
+
# IOStreams.add_root(:default, "tmp/export")
|
458
|
+
#
|
459
|
+
# IOStreams.join('file.xls')
|
460
|
+
# # => #<IOStreams::File::Path:0x00007fec70391bd8 @path="tmp/export/sample">
|
461
|
+
#
|
462
|
+
# IOStreams.join('file.xls').to_s
|
463
|
+
# # => "tmp/export/sample"
|
464
|
+
#
|
465
|
+
# IOStreams.join('sample', 'file.xls', root: :ftp)
|
466
|
+
# # => #<IOStreams::File::Path:0x00007fec6ee329b8 @path="tmp/ftp/sample/file.xls">
|
467
|
+
#
|
468
|
+
# IOStreams.join('sample', 'file.xls', root: :ftp).to_s
|
469
|
+
# # => "tmp/ftp/sample/file.xls"
|
470
|
+
#
|
471
|
+
# Notes:
|
472
|
+
# * Add the root path first against which this path is permitted to operate.
|
473
|
+
# `IOStreams.add_root(:default, "/usr/local/var/files")`
|
474
|
+
def self.join(*elements, root: :default)
|
475
|
+
root(root).join(*elements)
|
476
|
+
end
|
477
|
+
|
457
478
|
# Return named root path
|
458
|
-
def self.
|
479
|
+
def self.root(root = :default)
|
459
480
|
@roots_paths[root.to_sym] || raise(ArgumentError, "Unknown root: #{root.inspect}")
|
460
481
|
end
|
461
482
|
|
462
483
|
# Add a named root path
|
463
|
-
def self.
|
484
|
+
def self.add_root(root, *elements)
|
464
485
|
raise(ArgumentError, "Invalid root name #{root.inspect}") unless root.to_s =~ /\A\w+\Z/
|
465
486
|
|
466
|
-
|
467
|
-
path_class = IOStreams.scheme(uri.scheme).path_class
|
468
|
-
@roots_paths[root.to_sym] = path_class.new(path)
|
487
|
+
@roots_paths[root.to_sym] = path(*elements)
|
469
488
|
end
|
470
489
|
|
471
|
-
def self.
|
490
|
+
def self.roots
|
472
491
|
@roots_paths.dup
|
473
492
|
end
|
474
493
|
|
data/lib/io_streams/version.rb
CHANGED
data/test/path_test.rb
CHANGED
@@ -3,49 +3,49 @@ require_relative 'test_helper'
|
|
3
3
|
module IOStreams
|
4
4
|
class PathTest < Minitest::Test
|
5
5
|
describe IOStreams do
|
6
|
-
describe '.
|
6
|
+
describe '.root' do
|
7
7
|
it 'return default path' do
|
8
8
|
path = ::File.expand_path(::File.join(__dir__, '../tmp/default'))
|
9
|
-
assert_equal path, IOStreams.
|
9
|
+
assert_equal path, IOStreams.root.to_s
|
10
10
|
end
|
11
11
|
|
12
12
|
it 'return downloads path' do
|
13
13
|
path = ::File.expand_path(::File.join(__dir__, '../tmp/downloads'))
|
14
|
-
assert_equal path, IOStreams.
|
14
|
+
assert_equal path, IOStreams.root(:downloads).to_s
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
18
|
describe '.path' do
|
19
19
|
it 'returns path' do
|
20
|
-
assert_equal IOStreams.
|
20
|
+
assert_equal IOStreams.root.to_s, IOStreams.join.to_s
|
21
21
|
end
|
22
22
|
|
23
23
|
it 'adds path to root' do
|
24
|
-
assert_equal ::File.join(IOStreams.
|
24
|
+
assert_equal ::File.join(IOStreams.root.to_s, 'test'), IOStreams.join('test').to_s
|
25
25
|
end
|
26
26
|
|
27
27
|
it 'adds paths to root' do
|
28
|
-
assert_equal ::File.join(IOStreams.
|
28
|
+
assert_equal ::File.join(IOStreams.root.to_s, 'test', 'second', 'third'), IOStreams.join('test', 'second', 'third').to_s
|
29
29
|
end
|
30
30
|
|
31
31
|
it 'returns path and filename' do
|
32
|
-
path = ::File.join(IOStreams.
|
33
|
-
assert_equal path, IOStreams.
|
32
|
+
path = ::File.join(IOStreams.root.to_s, 'file.xls')
|
33
|
+
assert_equal path, IOStreams.join('file.xls').to_s
|
34
34
|
end
|
35
35
|
|
36
36
|
it 'adds path to root and filename' do
|
37
|
-
path = ::File.join(IOStreams.
|
38
|
-
assert_equal path, IOStreams.
|
37
|
+
path = ::File.join(IOStreams.root.to_s, 'test', 'file.xls')
|
38
|
+
assert_equal path, IOStreams.join('test', 'file.xls').to_s
|
39
39
|
end
|
40
40
|
|
41
41
|
it 'adds paths to root' do
|
42
|
-
path = ::File.join(IOStreams.
|
43
|
-
assert_equal path, IOStreams.
|
42
|
+
path = ::File.join(IOStreams.root.to_s, 'test', 'second', 'third', 'file.xls')
|
43
|
+
assert_equal path, IOStreams.join('test', 'second', 'third', 'file.xls').to_s
|
44
44
|
end
|
45
45
|
|
46
46
|
it 'return path as sent in when full path' do
|
47
|
-
path = ::File.join(IOStreams.
|
48
|
-
assert_equal path, IOStreams.
|
47
|
+
path = ::File.join(IOStreams.root.to_s, 'file.xls')
|
48
|
+
assert_equal path, IOStreams.join(path).to_s
|
49
49
|
end
|
50
50
|
end
|
51
51
|
end
|
data/test/test_helper.rb
CHANGED
@@ -35,5 +35,5 @@ end
|
|
35
35
|
|
36
36
|
# Test paths
|
37
37
|
root = File.expand_path(File.join(__dir__, '../tmp'))
|
38
|
-
IOStreams.
|
39
|
-
IOStreams.
|
38
|
+
IOStreams.add_root(:default, File.join(root, 'default'))
|
39
|
+
IOStreams.add_root(:downloads, File.join(root, 'downloads'))
|
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: 0.20.
|
4
|
+
version: 0.20.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Reid Morrison
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-08-
|
11
|
+
date: 2019-08-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|