Class: Pry::CodeFile

Inherits:
Object show all
Defined in:
lib/pry/code/code_file.rb

Constant Summary collapse

DEFAULT_EXT =
'.rb'.freeze
EXTENSIONS =

List of all supported languages.

Returns:

  • (Hash)
{
  %w[.py] => :python,
  %w[.js] => :javascript,
  %w[.css] => :css,
  %w[.xml] => :xml,
  %w[.php] => :php,
  %w[.html] => :html,
  %w[.diff] => :diff,
  %w[.java] => :java,
  %w[.json] => :json,
  %w[.c .h] => :c,
  %w[.rhtml] => :rhtml,
  %w[.yaml .yml] => :yaml,
  %w[.cpp .hpp .cc .h .cxx] => :cpp,
  %w[.rb .ru .irbrc .gemspec .pryrc .rake] => :ruby
}.freeze
FILES =
{
  %w[Gemfile Rakefile Guardfile Capfile] => :ruby
}.freeze
INITIAL_PWD =

Store the current working directory. This allows show-source etc. to work if your process has changed directory since boot. [Issue #675]

Dir.pwd

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename, code_type = type_from_filename(filename)) ⇒ CodeFile

Returns a new instance of CodeFile.

Parameters:

  • filename (String)

    The name of a file with code to be detected

  • code_type (Symbol) (defaults to: type_from_filename(filename))

    The type of code the ‘filename` contains



41
42
43
44
# File 'lib/pry/code/code_file.rb', line 41

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

Instance Attribute Details

#code_typeSymbol (readonly)

Returns The type of code stored in this wrapper.

Returns:

  • (Symbol)

    The type of code stored in this wrapper.



37
38
39
# File 'lib/pry/code/code_file.rb', line 37

def code_type
  @code_type
end

Instance Method Details

#codeString

Returns The code contained in the current ‘@filename`.

Returns:

  • (String)

    The code contained in the current ‘@filename`.



47
48
49
50
51
52
53
54
55
56
57
# File 'lib/pry/code/code_file.rb', line 47

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