iostreams 0.20.0 → 0.20.1

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: b16ce2bb98466540950ee6a40c9b3066630e99e7987c93621b3a175b5b027731
4
- data.tar.gz: 6fb4dd208cc04a71d78ac1355f8035159a97b67f2a749dc922df3f6edf7208ac
3
+ metadata.gz: d2c3b941a898cf14f2e8d5ac430f55efc602126f0d2e339014cb3de97d7c9233
4
+ data.tar.gz: e5745a12f24746ecf624627ac45e900251b0c3b83b109d7f18c04ffaf4efeba5
5
5
  SHA512:
6
- metadata.gz: e58da1ef631c0eae5574194e6586dbf7b52becc934a01a00ede0ef0f665d14f08391a5a2fee645bbe8ffe8fe8452c6d4b79eb84396f1e94e9b98ad9dea229041
7
- data.tar.gz: d821299bb5742832125ff2b7a6826f68b734967ea7a5f5d94cf1b619ef3ad82dfd2c457455a5d62523ca52832f5d17b7c2f343f5f387f77abdbeaca6bff42dd7
6
+ metadata.gz: ae879c20c587da2b9a2c5ae36a0488346b49f11470bd812640d6ccda161434221b98cdb65c5d7cc2988492621822a4e301665033e94207f90b323299b2e0fc24
7
+ data.tar.gz: a325782b46feeaf314a94f758be89d02b006fabfe824c91b2ac17309841980cab4cb9129318040426d9d6582bff6dd7345bc40f9234b0cd2e89c0d5555948335
@@ -425,50 +425,69 @@ module IOStreams
425
425
  end
426
426
  end
427
427
 
428
- # Return the complete path including supplied elements.
428
+ # Returns [Path] instance for the supplied complete path with optional scheme.
429
429
  #
430
430
  # Example:
431
- # IOStreams.path('sample')
432
- # # => "/default_root/sample"
431
+ # IOStreams.path("/usr", "local", "sample")
432
+ # # => #<IOStreams::File::Path:0x00007fec66e59b60 @path="/usr/local/sample">
433
433
  #
434
- # IOStreams.path('file.xls')
435
- # # => "/default_root/file.xls"
434
+ # IOStreams.path("/usr", "local", "sample").to_s
435
+ # # => "/usr/local/sample"
436
436
  #
437
- # IOStreams.path('sample', root: :ftp)
438
- # # => "/ftp_root/sample"
437
+ # IOStreams.path("s3://mybucket/path/file.xls")
438
+ # # => #<IOStreams::S3::Path:0x00007fec66e3a288, @path="s3://mybucket/path/file.xls">
439
439
  #
440
- # IOStreams.path('sample', 'file.xls', root: :ftp)
441
- # # => "/ftp_root/sample/file.xls"
440
+ # IOStreams.path("s3://mybucket/path/file.xls").to_s
441
+ # # => "s3://mybucket/path/file.xls"
442
442
  #
443
- # Notes:
444
- # * Add the root path first against which this path is permitted to operate.
445
- # `IOStreams.add_root_path(:default, "/usr/local/var/files")`
446
- def self.path(*elements, root: :default)
447
- root_path(root).join(*elements)
448
- end
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.root_path(root = :default)
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.add_root_path(root, path)
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
- uri = URI.parse(path.to_s)
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.root_paths
490
+ def self.roots
472
491
  @roots_paths.dup
473
492
  end
474
493
 
@@ -1,3 +1,3 @@
1
1
  module IOStreams
2
- VERSION = '0.20.0'
2
+ VERSION = '0.20.1'
3
3
  end
@@ -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 '.root_path' do
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.root_path.to_s
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.root_path(:downloads).to_s
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.root_path.to_s, IOStreams.path.to_s
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.root_path.to_s, 'test'), IOStreams.path('test').to_s
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.root_path.to_s, 'test', 'second', 'third'), IOStreams.path('test', 'second', 'third').to_s
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.root_path.to_s, 'file.xls')
33
- assert_equal path, IOStreams.path('file.xls').to_s
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.root_path.to_s, 'test', 'file.xls')
38
- assert_equal path, IOStreams.path('test', 'file.xls').to_s
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.root_path.to_s, 'test', 'second', 'third', 'file.xls')
43
- assert_equal path, IOStreams.path('test', 'second', 'third', 'file.xls').to_s
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.root_path.to_s, 'file.xls')
48
- assert_equal path, IOStreams.path(path).to_s
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
@@ -35,5 +35,5 @@ end
35
35
 
36
36
  # Test paths
37
37
  root = File.expand_path(File.join(__dir__, '../tmp'))
38
- IOStreams.add_root_path(:default, File.join(root, 'default'))
39
- IOStreams.add_root_path(:downloads, File.join(root, 'downloads'))
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.0
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-23 00:00:00.000000000 Z
11
+ date: 2019-08-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby