class Pry::CodeFile

def abs_path

Returns:
  • (String) - absolute path for the given `filename`.

Raises:
  • (MethodSource::SourceNotFoundError) - if the `filename` is not
def abs_path
  code_path.detect { |path| readable?(path) } ||
    raise(MethodSource::SourceNotFoundError,
          "Cannot open #{@filename.inspect} for reading.")
end

def code

Returns:
  • (String) - The code contained in the current `@filename`.
def code
  if @filename == Pry.eval_path
    Pry.line_buffer.drop(1)
  elsif Pry::Method::Patcher.code_for(@filename)
    Pry::Method::Patcher.code_for(@filename)
  else
    path = abs_path
    @code_type = type_from_filename(path)
    File.read(path)
  end
end

def code_path

Returns:
  • (Array) - All the paths that contain code that Pry can use for its
def code_path
  [from_pwd, from_pry_init_pwd, *from_load_path]
end

def from_load_path

Returns:
  • (String) -
def from_load_path
  $LOAD_PATH.map { |path| File.expand_path(@filename, path) }
end

def from_pry_init_pwd

Returns:
  • (String) -
def from_pry_init_pwd
  File.expand_path(@filename, INITIAL_PWD)
end

def from_pwd

Returns:
  • (String) -
def from_pwd
  File.expand_path(@filename, Dir.pwd)
end

def initialize(filename, code_type = type_from_filename(filename))

Parameters:
  • code_type (Symbol) -- The type of code the `filename` contains
  • filename (String) -- The name of a file with code to be detected
def initialize(filename, code_type = type_from_filename(filename))
  @filename = filename
  @code_type = code_type
end

def readable?(path)

Returns:
  • (Boolean) - if the path, with or without the default ext,

Parameters:
  • path (String) --
def readable?(path)
  File.readable?(path) && !File.directory?(path) ||
    File.readable?(path << DEFAULT_EXT)
end

def type_from_filename(filename, default = :unknown)

Returns:
  • (Symbol, nil) - The SyntaxHighlighter type of a file from its

Parameters:
  • default (Symbol) -- (:unknown) the file type to assume if none could be
  • filename (String) --
def type_from_filename(filename, default = :unknown)
  _, @code_type = EXTENSIONS.find do |k, _|
    k.any? { |ext| ext == File.extname(filename) }
  end || FILES.find do |k, _|
    k.any? { |file_name| file_name == File.basename(filename) }
  end
  code_type || default
end