Sean,
On 13 Feb 2018, at 14:39, Sean P. DeNigris <sean@clipperadams.com> wrote:
I'd like a hook to specify default values more dynamically. The use case is that I created a glue layer between Magritte and NeoCSV so one can meta-describe how to extract CSV fields into objects.
For example: ``` descriptionDate <magritteDescription>
^ MADateDescription new accessor: #date; priority: 400; propertyAt: #csvFieldName put: 'Date'; propertyAt: #csvReader put: [ :s | (s, '/2017') asDate ]; default: Date today; yourself ```
The problem is that there doesn't seem to be a way to plug #default: above into NeoCSV because other hooks like #addField:converter: seem to be skipped for nil values, shortcutting to a statically described per-csv-file emptyFieldValue.
The initial idea of the empty value (defaulting to nil) and the short circuiting of further conversion, is precisely to help in the writing of the converter blocks, so that [ :s | s asDate ] will never receive nil or an empty string and consequently does not have to test on it. I suppose I could imagine an option like #passEmptyFieldsToConverters, which would allow (and force you) to write converter blocks like [ :s | s isEmptyOrNil ifTrue: [ Date doomsDay ] ifFalse: [ s asDate ] ] so that you can specify your own custom empty value per field. What do you think ? Sven