Skip to content

Commit bfeed23

Browse files
committed
API improvements and added class comments and better names for the examples
1 parent 258aaf1 commit bfeed23

6 files changed

Lines changed: 44 additions & 24 deletions

File tree

src/MethodProxies/MpDeactivator.class.st

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
"
2+
I am a deactivator handler. When an exception or a non local return occurs, I will be executed just like an ensure:
3+
I am executed in the same way that an ensure does
4+
"
15
Class {
26
#name : 'MpDeactivator',
37
#superclass : 'Object',

src/MethodProxies/MpHandler.class.st

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,27 +19,37 @@ Class {
1919
#package : 'MethodProxies'
2020
}
2121

22-
{ #category : 'evaluating' }
22+
{ #category : 'evaluating - excepction or non local return' }
2323
MpHandler >> aboutToReturnWithReceiver: receiver arguments: arguments [
2424

25-
self afterExecutionWithReceiver: receiver arguments: arguments returnValue: nil
25+
^ self afterExecutionWithReceiver: receiver arguments: arguments returnValue: nil
2626
]
2727

2828
{ #category : 'evaluating' }
2929
MpHandler >> afterExecutionWithReceiver: anObject arguments: anArrayOfObjects returnValue: returnValue [
30+
"This is the method that you need to subclass if you want to execute the after method."
31+
32+
"IMPORTANT This method needs to ALWAYS return the object that the proxied method should return."
33+
"This object is normally the argument `returnValue`; or something else if you want to change the returned object."
34+
35+
self afterMethod.
36+
^ returnValue
37+
]
3038

31-
"This is the method that you need to subclass if you want to execute the after method."
32-
33-
"IMPORTANT!! This method needs to **ALWAYS** return the object that the proxied method should return."
34-
"This object is normally the argument `returnValue`; or something else if you want to change the returned object."
39+
{ #category : 'evaluating' }
40+
MpHandler >> afterMethod [
3541

36-
^ returnValue
42+
3743
]
3844

3945
{ #category : 'evaluating' }
4046
MpHandler >> beforeExecutionWithReceiver: anObject arguments: anArrayOfObjects [
4147

42-
"This is the method that you need to subclass if you want to execute a before action: an action that is executed before than the proxied method."
48+
self beforeMethod
49+
]
50+
51+
{ #category : 'evaluating' }
52+
MpHandler >> beforeMethod [
4353

44-
54+
4555
]

src/MethodProxies/MpMethodProxy.class.st

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1464,9 +1464,8 @@ MpMethodProxy >> methodClass [
14641464
{ #category : 'installation' }
14651465
MpMethodProxy >> prototypeTrapMethod [
14661466

1467-
^ self class class methods detect: [ :m |
1468-
m numArgs = proxifiedMethod numArgs and: [
1469-
m selector beginsWith: 'trap' ] ]
1467+
^ self class class methods detect: [ :m |
1468+
m numArgs = proxifiedMethod numArgs and: [ m selector beginsWith: 'trapMethod' ] ]
14701469
]
14711470

14721471
{ #category : 'accessing' }
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"
2+
I am an example hanlder that changes the return value of my instrumented method.
3+
4+
"
5+
Class {
6+
#name : 'MpChangesReturnValueHandler',
7+
#superclass : 'MpHandler',
8+
#category : 'MethodProxiesExamples',
9+
#package : 'MethodProxiesExamples'
10+
}
11+
12+
{ #category : 'evaluating' }
13+
MpChangesReturnValueHandler >> afterExecutionWithReceiver: receiver arguments: arguments returnValue: returnValue [
14+
15+
^ 'trapped [' , returnValue asString , ']'
16+
]

src/MethodProxiesExamples/MpCountingHandlerWithReceiver.class.st

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
"
2+
I am an example of a handler that counts how many times a method has been called and stores all the receivers
3+
"
14
Class {
25
#name : 'MpCountingHandlerWithReceiver',
36
#superclass : 'MpCountingHandler',

src/MethodProxiesExamples/MpMockMethodProxyHandler.class.st

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)