Class: Crispy::CrispyInternal::ClassSpy
- Inherits:
-
Module
- Object
- Module
- Crispy::CrispyInternal::ClassSpy
show all
- Includes:
- SpyMixin
- Defined in:
- lib/crispy/crispy_internal/class_spy.rb
Constant Summary
Constants included
from SpyMixin
SpyMixin::BLACK_LISTED_METHODS, SpyMixin::COMMON_RECEIVED_MESSAGE_METHODS_DEFINITION
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from SpyMixin
#assert_symbol!, #restart, #stop
Constructor Details
#initialize(klass) ⇒ ClassSpy
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/crispy/crispy_internal/class_spy.rb', line 13
def initialize klass spy = self
super() do
define_method(:__CRISPY_CLASS_SPY__) { spy }
end
@received_messages_with_receiver = []
initialize_spy
prepend_features klass
self.class.register spy: spy, of_class: klass
end
|
Class Method Details
.new(klass) ⇒ Object
83
84
85
86
87
88
89
90
91
92
|
# File 'lib/crispy/crispy_internal/class_spy.rb', line 83
def self.new klass spy = self.of_class(klass)
if spy
spy.restart
spy.erase_log
spy
else
super
end
end
|
.of_class(klass) ⇒ Object
98
99
100
|
# File 'lib/crispy/crispy_internal/class_spy.rb', line 98
def self.of_class(klass)
@registry[klass]
end
|
.register(spy: nil, of_class: nil) ⇒ Object
94
95
96
|
# File 'lib/crispy/crispy_internal/class_spy.rb', line 94
def self.register(spy: nil, of_class: nil)
@registry[of_class] = spy
end
|
Instance Method Details
#append_received_message_with_receiver(receiver, method_name, *arguments, &attached_block) ⇒ Object
66
67
68
69
70
71
|
# File 'lib/crispy/crispy_internal/class_spy.rb', line 66
def append_received_message_with_receiver receiver, method_name, *arguments, &attached_block
if @spying
@received_messages_with_receiver <<
::Crispy::CrispyReceivedMessageWithReceiver.new(receiver, method_name, *arguments, &attached_block)
end
end
|
#erase_log ⇒ Object
62
63
64
|
# File 'lib/crispy/crispy_internal/class_spy.rb', line 62
def erase_log
@received_messages_with_receiver.clear
end
|
#received_messages ⇒ Object
29
30
31
|
# File 'lib/crispy/crispy_internal/class_spy.rb', line 29
def received_messages
@received_messages_with_receiver.map {|m| m.received_message }
end
|
#received_messages_with_receiver ⇒ Object
33
34
35
36
37
|
# File 'lib/crispy/crispy_internal/class_spy.rb', line 33
def received_messages_with_receiver
self.stop
@received_messages_with_receiver
end
|