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



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/mutant/zombifier/file.rb', line 35

def self.find(logical_name)
  file_name =
    case ::File.extname(logical_name)
    when '.so'
      return
    when '.rb'
      logical_name
    else
      "#{logical_name}.rb"
    end

  $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

Returns:

  • (self)


13
14
15
16
17
18
19
20
21
# File 'lib/mutant/zombifier/file.rb', line 13

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