-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsnippet_prefix.rb
77 lines (66 loc) · 2.54 KB
/
snippet_prefix.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
require 'set'
require 'active_support'
require 'active_support/all'
require 'markaby'
popup_enabled = ENV["POPUPS"]
use_fake_root = ENV["FAKE_ROOT"]
if use_fake_root
def load_fake_root_to_hash(directory, h, i)
Dir["#{directory}/*"].each do |f|
components = f.split('/')
if File.directory? f
dirname = components[i]
h[dirname] = {}
load_fake_root_to_hash f, h[dirname], (i+1)
else
h[components.last] = File.read f
end
end
end
def load_to_fakefs_from_hash(h, directory)
FileUtils.mkdir(directory) unless File.exist? directory
h.each_pair do |name, content|
is_directory = content.is_a? Hash
if is_directory
load_to_fakefs_from_hash(content, directory + name + "/")
else
File.open(directory + name, 'w') do |f|
f.write content
end
end
end
end
directory_map = {}
load_fake_root_to_hash "fake-root", directory_map, 1
require 'fakefs'
load_to_fakefs_from_hash directory_map, "/"
else
require 'fakefs'
end
class File
def self.foreach(path)
self.read(path).each_line { |line| yield(line) }
end
end
class << IO
[:sysopen, :for_fd, :popen, :readlines, :read, :binread, :binwrite, :select, :pipe, :try_convert, :copy_stream, :remove_class_variable, :class_variable_get, :class_variable_set, :public_constant, :private_constant, :public_instance_method, :!~, :singleton_class, :untrust, :untrusted?, :trust, :remove_instance_variable, :tap, :public_send, :extend, :display, :method, :public_method, :define_singleton_method, :object_id, :to_enum, :enum_for, :__id__].each { |m| define_method( m) { |*args| undef_method m }}
end
class Object
remove_const :ENV
end
module Kernel
[:warn, :trace_var, :untrace_var, :at_exit, :syscall, :open, :gets, :readline, :select, :readlines, :`, :test, :srand, :rand, :trap, :exec, :fork, :exit!, :system, :spawn, :sleep, :exit, :abort, :load, :require, :require_relative, :caller, :caller_locations, :set_trace_func, :untrust, :untrusted?, :trust, :tap, :display].each { |m| undef_method m }
end
class << Kernel
[:warn, :trace_var, :untrace_var, :at_exit, :syscall, :open, :gets, :readline, :select, :readlines, :`, :test, :srand, :rand, :trap, :exec, :fork, :exit!, :system, :spawn, :sleep, :exit, :abort, :load, :require, :require_relative, :caller, :caller_locations, :set_trace_func].each { |m| undef_method m }
end
if popup_enabled
def require(name)
if name != "popup" || defined?(Popup)
false
else
eval File.read("/Libraries/#{name}.rb")
true
end
end
end