Method: InVFS.require_in

Defined in:
lib/invfs.rb

.require_in(vfs, path) ⇒ Object



120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/invfs.rb', line 120

def InVFS.require_in(vfs, path)
  code = String(vfs.read(path))
  loadpath = File.join(vfs, path)
  unless File.extname(path) == ".so"
    unless code.encoding == Encoding::UTF_8
      code = code.dup if code.frozen?
      code.force_encoding(Encoding::UTF_8)
    end

    eval code, InVFS::TOPLEVEL_BINDING.dup, loadpath, 1
  else
    Dir.mktmpdir do |dir|
      tempname = File.join(dir, File.basename(path))
      mode = File::CREAT | File::WRONLY | File::EXCL | File::BINARY
      File.open(tempname, mode, 0700) { |fd| fd << code }
      require! tempname
      $".pop # 偽装したライブラリパスであるため、削除
    end
  end

  $" << (LOADED_PREFIX + loadpath)

  true
end