Class: Mutant::Zombifier::File

Inherits:
Object
  • Object
show all
Includes:
Adamantium::Flat, AST::Sexp
Defined in:
lib/mutant/zombifier/file.rb

Overview

File containing source being zombified

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.find(logical_name) ⇒ File?

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Find file by logical path

Parameters:

  • logical_name (String)

Returns:

  • (File)

    if found

  • (nil)

    otherwise


39
40
41
42
43
44
45
46
47
48
49
# File 'lib/mutant/zombifier/file.rb', line 39

def self.find(logical_name)
  file_name = expand_file_name(logical_name)

  $LOAD_PATH.each do |path|
    path = Pathname.new(path).join(file_name)
    return new(path) if path.file?
  end

  $stderr.puts "Cannot find file #{file_name} in $LOAD_PATH"
  nil
end

Instance Method Details

#zombify(namespace) ⇒ self

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Zombify contents of file

Probably one of the only valid uses of eval.

rubocop:disable Lint/Eval

Returns:

  • (self)

17
18
19
20
21
22
23
24
25
# File 'lib/mutant/zombifier/file.rb', line 17

def zombify(namespace)
  $stderr.puts("Zombifying #{path}")
  eval(
    Unparser.unparse(namespaced_node(namespace)),
    TOPLEVEL_BINDING,
    path.to_s
  )
  self
end