Module: Ratonvirus::Scanner::Support::Callbacks

Included in:
Base
Defined in:
lib/ratonvirus/scanner/support/callbacks.rb

Overview

Provides a simple callbacks implementation to be used with the scanners.

We cannot use the ActiveSupport::Callbacks because that applies the callbacks to the whole class. We only want to define callbacks on the single instance of a class.

Defining new callbacks hooks to the instance:

class Cls
include Ratonvirus::Support::Callbacks

def initialize
  define_callbacks :hook
end
end

Triggering the callback hooks:

class Cls
# ...
def some_method
  run_callbacks :hook, resource do
    puts "... do something ..."
  end
end
# ...
end

Applying functionality to the hooks:

class Cls
def attach_callbacks
  before_hook :run_before
  after_hook :run_after
end

def run_before
  puts "This is run before the hook"
end

def run_after
  puts "This is run after the hook"
end
end