module ActiveSpy::Spy

Module that defines methods used to spy on some class methods

Public Class Methods

included(base) click to toggle source

Default snippet to extends the class with {ActiveSpy::Spy::ClassMethods} when {ActiveSpy::Spy} is included in it.

# File lib/active_spy/spy/spy.rb, line 10
def self.included(base)
  base.extend ClassMethods
end

Public Instance Methods

callback_invoker_class() click to toggle source

Gets the invoker class based on the class’ name

# File lib/active_spy/spy/spy.rb, line 26
def callback_invoker_class
  ActiveSupport::Inflector.constantize "#{self.class.name}Events"
end
invoke_callback(method, callback_type) click to toggle source

Invokes the callback method on the invoker class. The callback_type param tells wether it will be called :after or before.

# File lib/active_spy/spy/spy.rb, line 17
def invoke_callback(method, callback_type)
  callback_invoker = callback_invoker_class.new(self)
  callback = "#{callback_type}_#{method}"
  return unless callback_invoker.respond_to?(callback)
  callback_invoker.send(callback)
end