Skip to content

Commit

Permalink
Merge pull request #335 from seandenigris/enh_ma-print-string
Browse files Browse the repository at this point in the history
[Enh]: Print via Desc - `#maFullPrintString` & Separator Config
  • Loading branch information
seandenigris authored Sep 13, 2023
2 parents dd7f654 + bc7c2fc commit dac718b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
13 changes: 11 additions & 2 deletions source/Magritte-Model/MAContainer.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,16 @@ MAContainer >> postCopy [

{ #category : #accessing }
MAContainer >> print: anObject on: aStream [
"Print the current values of all anObject's described fields. Customize the printing of a field with the #maPrintString property, which should store a valuable with the value of the field as an optional argument"

"Print the current values of all anObject's described fields. Your can customize:
1) the printing of a field via the #maPrintString property, which should store a valuable with the value of the field as an optional argument
2) the field separator, via the maPrintStringSeparator property, which should store a valuable whose optional argument is the stream, and which should put separator thereon"

| separatorBlock |
separatorBlock := self
propertyAt: #maPrintStringSeparator
ifAbsent: [ [ aStream space ] ].

self
do: [ :d |
| value |
Expand All @@ -308,7 +317,7 @@ MAContainer >> print: anObject on: aStream [
ifPresent: [ :map | map cull: value ]
ifAbsent: [ d toString: value ].
aStream nextPutAll: stringValue ] ]
separatedBy: [ aStream space ]
separatedBy: [ separatorBlock cull: aStream ]
]

{ #category : #enumerating }
Expand Down
6 changes: 6 additions & 0 deletions source/Magritte-Model/Object.extension.st
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ Object >> isSameAs: rhs using: valuableDescription [
"Motivation: We cache the description because profiling on a large dataset (120,000 records) showed about 66% of processing time was spent (re)building it"
]

{ #category : #'*Magritte-Model' }
Object >> maFullPrintString [

^ String streamContents: [ :str | self maPrintOn: str ]
]

{ #category : #'*Magritte-Model' }
Object >> maHash [
^ self maHashUsing: [ self magritteDescription ]
Expand Down

0 comments on commit dac718b

Please sign in to comment.