Module: Staticky::Files::Path
- Defined in:
- lib/staticky/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 =
::File::SEPARATOR
- EMPTY_TOKEN =
""
Class Method Summary collapse
-
.absolute?(path) ⇒ TrueClass, FalseClass
Check if given path is absolute.
-
.call(*path) ⇒ String
(also: [])
Transform the given path into a path that respect the Operating System directory separator.
-
.dirname(path) ⇒ String
Returns all the path, except for the last token.
-
.split(path) ⇒ Array<String>
Split path according to the current Operating System directory separator.
Class Method Details
.absolute?(path) ⇒ TrueClass, FalseClass
Check if given path is absolute
81 82 83 |
# File 'lib/staticky/files/path.rb', line 81 def self.absolute?(path) path.start_with?(SEPARATOR) end |
.call(*path) ⇒ String Also known as: []
Transform the given path into a path that respect the Operating System directory separator.
transform
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/staticky/files/path.rb', line 52 def call(*path) path = Array(path).flatten tokens = path.map do |token| split(token) end tokens .flatten .join(SEPARATOR) end |
.dirname(path) ⇒ String
Returns all the path, except for the last token
90 91 92 |
# File 'lib/staticky/files/path.rb', line 90 def self.dirname(path) ::File.dirname(path) end |
.split(path) ⇒ Array<String>
Split path according to the current Operating System directory separator
70 71 72 73 74 |
# File 'lib/staticky/files/path.rb', line 70 def self.split(path) return EMPTY_TOKEN if path == SEPARATOR path.to_s.split(%r{\\|/}) end |