Module: Immunio::IOHooks

Defined in:
lib/immunio/plugins/io.rb

Class Method Summary collapse

Class Method Details

.inject(mod, name, methods) ⇒ Object



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
# File 'lib/immunio/plugins/io.rb', line 20

def self.inject(mod, name, methods)
  mod.class_eval "def self.extended(base)\n\#{methods.inspect}.each do |method|\nImmunio::Utils.alias_method_chain base.singleton_class, method, :immunio\nend\nend\n\ndef self.included(base)\n\#{methods.inspect}.each do |method|\nImmunio::Utils.alias_method_chain base, method, :immunio\nend\nend\n"
  Immunio.logger.debug { "IO: successfully chained #{name} #{methods}" }
  methods.each do |method|
    mod.class_eval "def \#{method}_with_immunio(*args, &block)                    # def read_with_immunio(*args, &block)\nif Immunio::IOHooks.paused?\n\#{method}_without_immunio(*args, &block)\nelse\nRequest.time \"plugin\", \"IO::\#{method}\" do                  #\nstrict_context, loose_context, stack = Immunio::Context.context()\n\nImmunio.run_hook! \"io\", \"file_io\",                       #   Immunio.run_hook! \"io\", \"open\",\nmethod: \"\#{name}\#{method}\",              #      open_method: \"IO.read\",\nparameters: args,                        #      parameters: args\nstack: stack,                            #\ncontext_key: loose_context,              #\ncwd: Dir.pwd\nRequest.pause \"plugin\", \"IO::\#{method}\" do               #\n\#{method}_without_immunio(*args, &block)               #   read_without_immunio(*args, &block)\nend\nend\nend\nend                                                          # end\n"
    Immunio.logger.debug { "IO: successfully created hook for #{name} #{method}" }
  end
end

.pausedObject



6
7
8
9
10
11
12
13
14
# File 'lib/immunio/plugins/io.rb', line 6

def self.paused
  old_paused = Thread.current["immunio.file_io_paused"]
  Thread.current["immunio.file_io_paused"] = true
  begin
    yield
  ensure
    Thread.current["immunio.file_io_paused"] = old_paused
  end
end

.paused?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/immunio/plugins/io.rb', line 16

def self.paused?
  !!Thread.current["immunio.file_io_paused"]
end