Skip to content

Commit

Permalink
Merge pull request #361 from seandenigris/enh_messaging-string-writer
Browse files Browse the repository at this point in the history
[Enh]: MAMessagingStringWriter
  • Loading branch information
seandenigris authored Aug 16, 2024
2 parents 5925076 + 255504c commit 5b41060
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions source/Magritte-Model/MAMessagingStringWriter.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
"
I enable delegating string writing to an arbitrary object via any of its messages.
*Limitation:* I cannot be used when 1) the message receiver is the container and 2) descriptions are cached e.g. when using the description for the first object in a homogeneous collection for the whole collection.
Here is an example (which illustrates #1 in the limitation above and so wouldn't work with a cached description):
```
MyDomainClass>>employeeDescription
<magritteDescription>
| message writer reference |
message := MessageSend
receiver: self
selector: #employeeDisplayString.
writer := MAMessagingStringWriter new
messageSend: message.
reference := MAContainer new
stringWriter: writer;
yourself.
^ MAToOneRelationDescription new
reference: reference;
accessor: #employee;
yourself
```
"
Class {
#name : #MAMessagingStringWriter,
#superclass : #MAStringWriter,
#instVars : [
'messageSend'
],
#category : #'Magritte-Model-Visitor'
}

{ #category : #accessing }
MAMessagingStringWriter >> messageSend [
^ messageSend
]

{ #category : #accessing }
MAMessagingStringWriter >> messageSend: anObject [
Halt if: [ anObject receiver employee isNil ].
messageSend := anObject
]

{ #category : #accessing }
MAMessagingStringWriter >> visitContainer: aDescription [

self visitDescription: aDescription
]

{ #category : #'as yet unclassified' }
MAMessagingStringWriter >> visitDescription: aDescription [

self stream nextPutAll: self messageSend value
]

{ #category : #'as yet unclassified' }
MAMessagingStringWriter >> visitElementDescription: aDescription [

self visitDescription: aDescription
]

0 comments on commit 5b41060

Please sign in to comment.