Sha256: 82f4decec52303665b827c11561c38c26faec39d149f453443f898199f32ccf7
Contents?: true
Size: 1.2 KB
Versions: 25
Compression:
Stored size: 1.2 KB
Contents
require 'active_support' module ActiveSpy # Module that defines methods used to spy on some class methods # module Spy # Default snippet to extends the class with {ActiveSpy::Spy::ClassMethods} # when {ActiveSpy::Spy} is included in it. # def self.included(base) base.extend ClassMethods end # Invokes the callback method on the invoker class. The +callback_type+ # param tells wether it will be called +:after+ or +before+. # 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 # Gets the invoker class based on the class' name # def callback_invoker_class ActiveSupport::Inflector.constantize "#{self.class.name}Events" end # Class methods to be defined in classes that includes {ActiveSpy::Spy} # module ClassMethods # Set watchers for the +method+ # def watch_method(*methods) methods.each do |method| ActiveSpy::SpyList << { 'class' => name, 'method' => method } end end end end end
Version data entries
25 entries across 25 versions & 1 rubygems