Skip to content

Commit f456e90

Browse files
authored
Merge pull request #100 from moosetechnology/use-setter
Use setter if a property is not found on import
2 parents 2341771 + ad617e9 commit f456e90

1 file changed

Lines changed: 17 additions & 3 deletions

File tree

src/Fame-ImportExport/Object.extension.st

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,24 @@ Extension { #name : #Object }
22

33
{ #category : #'*Fame-ImportExport' }
44
Object >> handleFameProperty: aSymbol value: anObject [
5-
"override me if you want your object to deal with undefined properties loaded from MSE"
5+
"Override me if you want your object to deal with undefined properties loaded from a JSON.
6+
7+
By default I'm logging the error and checking if we have a setter not metadescribed with the name of the property to execute. I return true if this is the case."
68

7-
self traceCr:
8-
'Unknown property ''' , aSymbol , ''' in ' , self class asString
9+
| setter |
10+
setter := aSymbol asSymbol asMutator.
11+
self traceCr: 'Unknown property ''' , aSymbol , ''' in ' , self class asString.
12+
13+
^ (self respondsTo: setter)
14+
ifTrue: [
15+
| value |
16+
value := (anObject isCollection and: [ anObject size = 1 ])
17+
ifTrue: [ anObject anyOne ]
18+
ifFalse: [ anObject ].
19+
self traceCr: 'Setter of the same name than the property detected. Falling back to this method.'.
20+
self perform: setter with: value.
21+
true ]
22+
ifFalse: [ false ]
923
]
1024

1125
{ #category : #'*Fame-ImportExport' }

0 commit comments

Comments
 (0)