module InVFS
Constants
- DEFAULT_MAX_LOADSIZE
- LOADED_PREFIX
+$LOADED_FEATURES+ に追加される接頭辞
- MAXIMAM_MAX_LOADSIZE
- MAX_LOADSIZE
- MINIMAL_MAX_LOADSIZE
- MultipleDirectory
- TOPLEVEL_BINDING
Public Class Methods
findlib(vfs, lib, relative)
click to toggle source
# File lib/invfs.rb, line 26 def InVFS.findlib(vfs, lib, relative) if relative if vfs.file?(lib) lib else nil end else case when vfs.file?(lib) lib when vfs.file?(librb = lib + ".rb") librb when vfs.file?(libso = lib + ".so") libso else nil end end end
findpath(absolute_lib_path, relative) { |vfs, subpath| ... }
click to toggle source
# File lib/invfs.rb, line 60 def InVFS.findpath(lib, relative) if relative || Pathname(lib).absolute? # 絶対パス表記でのライブラリ指定、または require_relative の呼び出し元 # NOTE: LOAD_PATH ($:) の順序を優先するか? # NOTE: 一致するティレクトリ階層の深さを優先するか? # NOTE: => とりあえずは順序を優先しておく $:.each do |vfs| #__BREAKHERE__ dir = String(vfs.to_path) dir += "/" unless dir.empty? || dir[-1] == "/" (a, b, c) = lib.partition(dir) next unless a.empty? && !b.empty? && !c.empty? next unless vfs = mapvfs(vfs) yield(vfs, c) end else $:.each do |vfs| next unless vfs = mapvfs(vfs) yield(vfs, lib) end end nil end
findvfs(lib, relative)
click to toggle source
# File lib/invfs.rb, line 47 def InVFS.findvfs(lib, relative) findpath(lib, relative) do |vfs, sub| next unless sub = findlib(vfs, sub, relative) return nil if vfs.__native_file_path? next if vfs.size(sub) > MAX_LOADSIZE return [vfs, sub] end end
loaded?(vfs, lib)
click to toggle source
# File lib/invfs.rb, line 116 def InVFS.loaded?(vfs, lib) !!$".include?(LOADED_PREFIX + File.join(vfs, lib)) end
mapvfs(vfs)
click to toggle source
# File lib/invfs.rb, line 102 def InVFS.mapvfs(vfs) return vfs unless vfs.it_a_file? v = @mapped_list[vfs] return v if v @handler_list.each do |handler| next unless handler.probe(vfs) return @mapped_list[vfs] = handler.open(vfs) end nil end
regist(handler)
click to toggle source
# File lib/invfs.rb, line 90 def InVFS.regist(handler) unless handler.respond_to?(:probe) && handler.respond_to?(:open) raise "%s - #<%s:0x08x>" % ["need ``.probe'' and ``.open'' methods for vfs handler", handler.class, handler.object_id] end @handler_list << handler nil end
require_in(vfs, path)
click to toggle source
# 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
stringmap(*map)
click to toggle source
# File lib/invfs.rb, line 183 def InVFS.stringmap(*map) require_relative "invfs/stringmapfs" StringMapFS.new(*map) end
union(*dirs)
click to toggle source
# File lib/invfs.rb, line 177 def InVFS.union(*dirs) require_relative "invfs/unionfs" UnionFS.new(*dirs) end
zip(*args)
click to toggle source
# File lib/invfs.rb, line 189 def InVFS.zip(*args) require_relative "invfs/zip" Zip.new(*args) end