Class: CodeFile

Inherits:
Object
  • Object
show all
Defined in:
lib/puppet-debugger/code/code_file.rb

Defined Under Namespace

Classes: SourceNotFound

Constant Summary collapse

DEFAULT_EXT =
'.pp'
EXTENSIONS =

List of all supported languages.

Returns:

  • (Hash)
{
  %w[.py] => :python,
  %w[.js] => :javascript,
  %w[.pp] => :puppet,
  %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] => :ruby
}.freeze

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



34
35
36
37
# File 'lib/puppet-debugger/code/code_file.rb', line 34

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.



30
31
32
# File 'lib/puppet-debugger/code/code_file.rb', line 30

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`.



40
41
42
43
44
# File 'lib/puppet-debugger/code/code_file.rb', line 40

def code
  path = abs_path
  @code_type = type_from_filename(path)
  File.read(path)
end