class Racket::Utils::FileSystem::PathBuilder

Build path in the filesystem.

Attributes

path[R]

Public Class Methods

new(root_dir, args) click to toggle source
# File lib/racket/utils/file_system.rb, line 58
def initialize(root_dir, args)
  @root_dir = root_dir
  extract_base_path(args.dup)
  build_path
  clean_path
end
to_pathname(root_dir, *args) click to toggle source

Creates a new instance of PathBuilder using args and then returning the final path as a Pathname.

@param [Array] args @return [Pathname]

# File lib/racket/utils/file_system.rb, line 50
def self.to_pathname(root_dir, *args)
  new(root_dir, args).path
end

Private Instance Methods

build_path() click to toggle source
# File lib/racket/utils/file_system.rb, line 79
def build_path
  @args.each do |arg|
    path_part = Pathname.new(arg)
    raise ArgumentError, arg unless path_part.relative?
    @path = @path.join(path_part)
  end
  remove_instance_variable :@args
end
clean_path() click to toggle source
# File lib/racket/utils/file_system.rb, line 65
def clean_path
  @path = @path.cleanpath.expand_path
end
extract_base_path(args) click to toggle source
# File lib/racket/utils/file_system.rb, line 69
def extract_base_path(args)
  if (@args = args).empty?
    @path = Pathname.pwd
    return
  end
  @args.map!(&:to_s)
  @path = Pathname.new(@args.shift)
  @path = Pathname.new(@root_dir).join(@path) if @path.relative?
end