Class: Ace::Support::Nav::Atoms::PathNormalizer

Inherits:
Object
  • Object
show all
Defined in:
lib/ace/support/nav/atoms/path_normalizer.rb

Overview

Normalizes and expands paths

Instance Method Summary collapse

Instance Method Details

#basename(path, suffix = nil) ⇒ Object



29
30
31
# File 'lib/ace/support/nav/atoms/path_normalizer.rb', line 29

def basename(path, suffix = nil)
  suffix ? File.basename(path, suffix) : File.basename(path)
end

#directory?(path) ⇒ Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/ace/support/nav/atoms/path_normalizer.rb', line 41

def directory?(path)
  File.directory?(path)
end

#dirname(path) ⇒ Object



25
26
27
# File 'lib/ace/support/nav/atoms/path_normalizer.rb', line 25

def dirname(path)
  File.dirname(path)
end

#exists?(path) ⇒ Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/ace/support/nav/atoms/path_normalizer.rb', line 37

def exists?(path)
  File.exist?(path)
end

#extname(path) ⇒ Object



33
34
35
# File 'lib/ace/support/nav/atoms/path_normalizer.rb', line 33

def extname(path)
  File.extname(path)
end

#file?(path) ⇒ Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/ace/support/nav/atoms/path_normalizer.rb', line 45

def file?(path)
  File.file?(path)
end

#join_paths(*parts) ⇒ Object



21
22
23
# File 'lib/ace/support/nav/atoms/path_normalizer.rb', line 21

def join_paths(*parts)
  File.join(*parts.compact)
end

#normalize(path) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/ace/support/nav/atoms/path_normalizer.rb', line 9

def normalize(path)
  return nil if path.nil? || path.empty?

  # Expand home directory
  path = File.expand_path(path) if path.start_with?("~")

  # Resolve relative paths
  path = File.expand_path(path) unless path.start_with?("/")

  path
end