class PathList::RootCandidate

Attributes

full_path[R]

Public Class Methods

new(full_path, filename, directory, content) click to toggle source
# File lib/path_list/root_candidate.rb, line 7
def initialize(full_path, filename, directory, content)
  @full_path = full_path
  @filename = filename
  (@directory = directory) unless directory.nil?
  @first_line = content
end

Public Instance Methods

directory?() click to toggle source
# File lib/path_list/root_candidate.rb, line 29
def directory?
  return @directory if defined?(@directory)

  @directory ||= ::File.directory?(@full_path)
end
filename() click to toggle source
# File lib/path_list/root_candidate.rb, line 35
def filename
  @filename ||= ::File.basename(@full_path)
end
first_line() click to toggle source

how long can a shebang be? www.in-ulm.de/~mascheck/various/shebang/ 512 feels like a reasonable limit

# File lib/path_list/root_candidate.rb, line 42
def first_line # rubocop:disable Metrics/MethodLength
  @first_line ||= begin
    file = ::File.new(@full_path)
    first_line = new_fragment = file.sysread(512)
    file.close
    first_line || ''
  rescue ::EOFError, ::SystemCallError
    # :nocov:
    file&.close
    # :nocov:
    first_line || ''
  end
end
parent() click to toggle source
# File lib/path_list/root_candidate.rb, line 14
def parent
  @parent ||= ::PathList::RootCandidate.new(
    ::File.dirname(@full_path),
    nil,
    true,
    nil
  )
end
relative_to(dir) click to toggle source
# File lib/path_list/root_candidate.rb, line 23
def relative_to(dir)
  return unless @full_path.start_with?(dir)

  ::PathList::RelativeCandidate.new(@full_path.delete_prefix(dir), self)
end