dry-files 0.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.
@@ -0,0 +1,112 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Dry
4
+ class Files
5
+ # Cross Operating System path
6
+ #
7
+ # It's used by the memory adapter to ensure that hardcoded string paths
8
+ # are transformed into portable paths that respect the Operating System
9
+ # directory separator.
10
+ module Path
11
+ # @since 0.1.0
12
+ # @api private
13
+ SEPARATOR = ::File::SEPARATOR
14
+
15
+ # @since 0.1.0
16
+ # @api private
17
+ EMPTY_TOKEN = ""
18
+ private_constant :EMPTY_TOKEN
19
+
20
+ class << self
21
+ # Transform the given path into a path that respect the Operating System
22
+ # directory separator.
23
+ #
24
+ # @param path [String,Pathname,Array<String,Pathname>] the path to transform
25
+ #
26
+ # @return [String] the resulting path
27
+ #
28
+ # @since 0.1.0
29
+ # @api private
30
+ #
31
+ # @example Portable Path
32
+ # require "dry/files/path"
33
+ #
34
+ # path = "path/to/file"
35
+ #
36
+ # Dry::Files::Path.call(path)
37
+ # # => "path/to/file" on UNIX based Operating System
38
+ #
39
+ # Dry::Files::Path.call(path)
40
+ # # => "path\to\file" on Windows Operating System
41
+ #
42
+ # @example Join Nested Tokens
43
+ # require "dry/files/path"
44
+ #
45
+ # path = ["path", ["to", ["nested", "file"]]]
46
+ #
47
+ # Dry::Files::Path.call(path)
48
+ # # => "path/to/nested/file" on UNIX based Operating System
49
+ #
50
+ # Dry::Files::Path.call(path)
51
+ # # => "path\to\nested\file" on Windows Operating System
52
+ #
53
+ # @example Separator path
54
+ # require "dry/files/path"
55
+ #
56
+ # path = ::File::SEPARATOR
57
+ #
58
+ # Dry::Files::Path.call(path)
59
+ # # => ""
60
+ def call(*path)
61
+ path = Array(path).flatten
62
+ tokens = path.map do |token|
63
+ split(token)
64
+ end
65
+
66
+ tokens
67
+ .flatten
68
+ .join(SEPARATOR)
69
+ end
70
+ alias_method :[], :call
71
+ end
72
+
73
+ # Split path according to the current Operating System directory separator
74
+ #
75
+ # @param path [String,Pathname] the path to split
76
+ #
77
+ # @return [Array<String>] the split path
78
+ #
79
+ # @since 0.1.0
80
+ # @api private
81
+ def self.split(path)
82
+ return EMPTY_TOKEN if path == SEPARATOR
83
+
84
+ path.to_s.split(%r{\\|/})
85
+ end
86
+
87
+ # Check if given path is absolute
88
+ #
89
+ # @param path [String,Pathname] the path to check
90
+ #
91
+ # @return [TrueClass,FalseClass] the result of the check
92
+ #
93
+ # @since 0.1.0
94
+ # @api private
95
+ def self.absolute?(path)
96
+ path.start_with?(SEPARATOR)
97
+ end
98
+
99
+ # Returns all the path, except for the last token
100
+ #
101
+ # @param path [String,Pathname] the path to extract directory name from
102
+ #
103
+ # @return [String] the directory name
104
+ #
105
+ # @since 0.1.0
106
+ # @api private
107
+ def self.dirname(path)
108
+ ::File.dirname(path)
109
+ end
110
+ end
111
+ end
112
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Dry
4
+ class Files
5
+ VERSION = "0.1.0"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dry-files
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Luca Guidi
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-05-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '13.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '13.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.10'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.10'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rubocop
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.12'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.12'
55
+ description: file utilities
56
+ email:
57
+ - me@lucaguidi.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - CHANGELOG.md
63
+ - LICENSE
64
+ - README.md
65
+ - dry-files.gemspec
66
+ - lib/dry-files.rb
67
+ - lib/dry/files.rb
68
+ - lib/dry/files/adapter.rb
69
+ - lib/dry/files/error.rb
70
+ - lib/dry/files/file_system.rb
71
+ - lib/dry/files/memory_file_system.rb
72
+ - lib/dry/files/memory_file_system/node.rb
73
+ - lib/dry/files/path.rb
74
+ - lib/dry/files/version.rb
75
+ homepage: https://dry-rb.org/gems/dry-files
76
+ licenses:
77
+ - MIT
78
+ metadata:
79
+ allowed_push_host: https://rubygems.org
80
+ changelog_uri: https://github.com/dry-rb/dry-files/blob/master/CHANGELOG.md
81
+ source_code_uri: https://github.com/dry-rb/dry-files
82
+ bug_tracker_uri: https://github.com/dry-rb/dry-files/issues
83
+ post_install_message:
84
+ rdoc_options: []
85
+ require_paths:
86
+ - lib
87
+ required_ruby_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: 2.5.0
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ requirements: []
98
+ rubygems_version: 3.1.6
99
+ signing_key:
100
+ specification_version: 4
101
+ summary: file utilities
102
+ test_files: []