Module: ActiveSpy::Spy
- Defined in:
- lib/active_spy/spy/spy.rb
Overview
Module that defines methods used to spy on some class methods
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
-
.included(base) ⇒ Object
Default snippet to extends the class with ClassMethods when Spy is included in it.
Instance Method Summary collapse
-
#callback_invoker_class ⇒ Object
Gets the invoker class based on the class’ name.
-
#invoke_callback(method, callback_type) ⇒ Object
Invokes the callback method on the invoker class.
Class Method Details
.included(base) ⇒ Object
Default snippet to extends the class with ClassMethods when ActiveSpy::Spy is included in it.
10 11 12 |
# File 'lib/active_spy/spy/spy.rb', line 10 def self.included(base) base.extend ClassMethods end |
Instance Method Details
#callback_invoker_class ⇒ Object
Gets the invoker class based on the class’ name
26 27 28 |
# 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) ⇒ Object
Invokes the callback method on the invoker class. The callback_type param tells wether it will be called :after or before.
17 18 19 20 21 22 |
# 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 |