Module: Primer::Watcher
- Extended by:
- Enabler
- Included in:
- Cache
- Defined in:
- lib/primer/watcher.rb,
lib/primer/watcher/macros.rb,
lib/primer/watcher/active_record_macros.rb
Defined Under Namespace
Modules: ActiveRecordMacros, Macros
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Enabler
disable!, enable!, enabled?
Class Method Details
.call_log ⇒ Object
17
18
19
|
# File 'lib/primer/watcher.rb', line 17
def self.call_log
Thread.current[:primer_call_log] ||= []
end
|
.included(klass) ⇒ Object
8
9
10
|
# File 'lib/primer/watcher.rb', line 8
def self.included(klass)
klass.extend(Macros)
end
|
.log(receiver, method_name, args, block, result) ⇒ Object
21
22
23
24
|
# File 'lib/primer/watcher.rb', line 21
def self.log(receiver, method_name, args, block, result)
call = [receiver, method_name, args, block, result]
loggers.each { |logger| logger << call }
end
|
.loggers ⇒ Object
26
27
28
|
# File 'lib/primer/watcher.rb', line 26
def self.loggers
Thread.current[:primer_loggers] ||= [call_log]
end
|
.on_disable ⇒ Object
34
35
36
|
# File 'lib/primer/watcher.rb', line 34
def self.on_disable
ObjectSpace.each_object(Macros) { |klass| klass.unpatch_for_primer! }
end
|
.on_enable ⇒ Object
30
31
32
|
# File 'lib/primer/watcher.rb', line 30
def self.on_enable
ObjectSpace.each_object(Macros) { |klass| klass.patch_for_primer! }
end
|
.reset! ⇒ Object
12
13
14
15
|
# File 'lib/primer/watcher.rb', line 12
def self.reset!
Thread.current[:primer_call_log] = []
Thread.current[:primer_loggers] = nil
end
|
.watching(calls = []) ⇒ Object
38
39
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/primer/watcher.rb', line 38
def self.watching(calls = [])
@active_watching_blocks ||= 0
@active_watching_blocks += 1
was_enabled = enabled?
enable!
loggers << calls
result = yield
loggers.pop
@active_watching_blocks -= 1
disable! if @active_watching_blocks.zero? and not was_enabled
result
end
|
Instance Method Details
#primer_identifier ⇒ Object
51
52
53
|
# File 'lib/primer/watcher.rb', line 51
def primer_identifier
['Object', self.class.name, object_id]
end
|