Module: Bparity::Formal::Assumptions::RuntimeMonitor

Defined in:
lib/bparity/formal/assumptions.rb

Defined Under Namespace

Modules: Hook, SingletonHook

Constant Summary collapse

THREAD_KEY =
:bparity_assumption_monitor

Class Method Summary collapse

Class Method Details

.capture(classes) ⇒ Object



32
33
34
35
36
37
38
39
# File 'lib/bparity/formal/assumptions.rb', line 32

def capture(classes)
  install!
  previous = Thread.current[THREAD_KEY]
  context = Thread.current[THREAD_KEY] = { classes:, violations: [] }
  [yield, context.fetch(:violations)]
ensure
  Thread.current[THREAD_KEY] = previous
end

.install!Object



48
49
50
51
52
53
# File 'lib/bparity/formal/assumptions.rb', line 48

def install!
  return if Module.ancestors.include?(Hook)

  Module.prepend(Hook)
  Object.prepend(SingletonHook)
end

.record(target, change) ⇒ Object



41
42
43
44
45
46
# File 'lib/bparity/formal/assumptions.rb', line 41

def record(target, change)
  context = Thread.current[THREAD_KEY]
  return unless context&.fetch(:classes)&.include?(target)

  context.fetch(:violations) << "H1: #{target.name || target.inspect} #{change} during verification"
end