Module: Dry::Files::Path
- Defined in:
- lib/dry/files/path.rb
Overview
Cross Operating System path
It’s used by the memory adapter to ensure that hardcoded string paths are transformed into portable paths that respect the Operating System directory separator.
Constant Summary collapse
- SEPARATOR =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
::File::SEPARATOR
Class Method Summary collapse
-
.absolute?(path) ⇒ TrueClass, FalseClass
private
Check if given path is absolute.
-
.call(*path) ⇒ String
(also: [])
private
Transform the given path into a path that respect the Operating System directory separator.
-
.dirname(path) ⇒ String
private
Returns all the path, except for the last token.
-
.split(path) ⇒ Array<String>
private
Split path according to the current Operating System directory separator.
Class Method Details
.absolute?(path) ⇒ TrueClass, FalseClass
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Check if given path is absolute
95 96 97 |
# File 'lib/dry/files/path.rb', line 95 def self.absolute?(path) path.start_with?(SEPARATOR) end |
.call(*path) ⇒ String Also known as: []
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Transform the given path into a path that respect the Operating System directory separator.
60 61 62 63 64 65 66 67 68 69 |
# File 'lib/dry/files/path.rb', line 60 def call(*path) path = Array(path).flatten tokens = path.map do |token| split(token) end tokens .flatten .join(SEPARATOR) end |
.dirname(path) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns all the path, except for the last token
107 108 109 |
# File 'lib/dry/files/path.rb', line 107 def self.dirname(path) ::File.dirname(path) end |
.split(path) ⇒ Array<String>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Split path according to the current Operating System directory separator
81 82 83 84 85 |
# File 'lib/dry/files/path.rb', line 81 def self.split(path) return EMPTY_TOKEN if path == SEPARATOR path.to_s.split(%r{\\|/}) end |