Class: ActiveSpy::SpyList
- Inherits:
-
Object
- Object
- ActiveSpy::SpyList
- Includes:
- Singleton
- Defined in:
- lib/active_spy/spy/spy_list.rb
Overview
Singleton used to hold the spies and lazely active these spies by patching the methods in the specified classes.
Instance Attribute Summary collapse
-
#spies ⇒ Object
readonly
Returns the value of attribute spies.
Class Method Summary collapse
Instance Method Summary collapse
-
#<<(other) ⇒ Object
forward #<< method to the spy list.
-
#activate ⇒ Object
Activate all the spies defined in the spy list by patching the methods in their classes.
-
#deactivate ⇒ Object
Deactivate all the spies defined in the spy list by unpatching the methods in their classes.
-
#initialize ⇒ SpyList
constructor
Just to initiliaze the spy list.
Constructor Details
#initialize ⇒ SpyList
Just to initiliaze the spy list.
13 14 15 |
# File 'lib/active_spy/spy/spy_list.rb', line 13 def initialize @spies = [] end |
Instance Attribute Details
#spies ⇒ Object (readonly)
Returns the value of attribute spies.
17 18 19 |
# File 'lib/active_spy/spy/spy_list.rb', line 17 def spies @spies end |
Class Method Details
.method_missing(method, *args, &block) ⇒ Object
Proxy all methods called in the ActiveSpy::SpyList class to a ActiveSpy::SpyList instance. Just a syntax sugar.
22 23 24 |
# File 'lib/active_spy/spy/spy_list.rb', line 22 def self.method_missing(method, *args, &block) instance.send(method, *args, &block) end |
Instance Method Details
#<<(other) ⇒ Object
forward #<< method to the spy list.
51 52 53 |
# File 'lib/active_spy/spy/spy_list.rb', line 51 def <<(other) @spies << other end |
#activate ⇒ Object
Activate all the spies defined in the spy list by patching the methods in their classes.
29 30 31 32 33 34 35 36 37 |
# File 'lib/active_spy/spy/spy_list.rb', line 29 def activate @spies.each do |spy| spied_class = spy['class'] spied_method = spy['method'] spy['old_method'] = patch(spied_class, spied_method) unless spy['active'] spy['active'] = true end end |
#deactivate ⇒ Object
Deactivate all the spies defined in the spy list by unpatching the methods in their classes.
42 43 44 45 46 47 |
# File 'lib/active_spy/spy/spy_list.rb', line 42 def deactivate @spies.each do |spy| unpatch(spy['class'], spy['method'], spy['old_method']) spy['active'] = nil end end |