Skip to content

Commit

Permalink
Merge pull request #50 from seandenigris/doc_method-comment-2si
Browse files Browse the repository at this point in the history
[Doc]: Better Comment for MA Two Stage Importer Helper Method
  • Loading branch information
seandenigris authored Aug 6, 2024
2 parents 80e800b + 9c2c964 commit bd8a52e
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions repository/Neo-CSV-Magritte/MACSVTwoStageImporter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,24 @@ Sometimes, you just can't fully create your domain objects from CSV in one pass.
- Multiple rows combine into one object (`inject:into:` can be helpful here)
- Multiple cells combine into one object field
To handle such a case, subclass me and, at minimum, override `#convertToDomainObjects:`. See its comment for more info. Implementations of that method often utilize my `#initializeDomainObject:fromRecord:` helper method.
To handle such a case, subclass me and, at minimum, override `#domainObjectFromDictionary:`. See its comment for more info. Implementations of that method often utilize my `#initializeDomainObject:fromRecord:` helper method.
##Combining Multiple Cells into One Field
Typically, you would override `domainObjectFromDictionary:`, do a super send, and then
Ideally, you would have a domain value object whose state is represented by these fields. If so, a common pattern is to and pass this object to `` like so:
```smalltalk
result := super domainObjectFromDictionary: aDictionary.
aValueObject := self
initializeDomainObject: MyValueObject new
fromRecord: aDictionary.
^ result
fooBar: aValueObject;
yourself
```
If the object can't be created anew - say it lives in a registry - you can always just pull
"
Class {
#name : #MACSVTwoStageImporter,
Expand Down Expand Up @@ -88,12 +105,12 @@ MACSVTwoStageImporter >> initializeDomainObject: anObject fromRecord: aDictionar

{ #category : #accessing }
MACSVTwoStageImporter >> initializeDomainObject: anObject fromRecord: aDictionary mapping: mapBlock descriptionDo: descriptionBlock [
"
anObject - domain object to be initialized
aDictionary - keys are CSV column names
mapBlock - use to modify existing descriptions; argument will be an MACSVMappingPragmaBuilder to configure
descriptionBlock - argument is the container description for anObject, for further configuration e.g. adding an element description"

"Send me only if you want to customize the domain object's Magritte description. Otherwise send one of the similar messages omitting the #descriptionDo: argument because my usage may seem a bit verbose due to creation of MADescriptions by hand, but I provide advantages - like gracefully handling nils. My arguments are as follows:
anObject - domain object to be initialized
aDictionary - keys are CSV column names
mapBlock - use to modify existing descriptions; argument will be an MACSVMappingPragmaBuilder to configure
descriptionBlock - argument is the container description for anObject, for further configuration e.g. adding an element description"
| contDesc builder |
builder := MACSVMappedPragmaBuilder new
fieldNamePropertyKey: self fieldNamePropertyKey;
Expand Down

0 comments on commit bd8a52e

Please sign in to comment.