Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Defining an instance creation method for recordClass #23

Open
JoachimTuchel opened this issue Apr 27, 2021 · 1 comment
Open

Defining an instance creation method for recordClass #23

JoachimTuchel opened this issue Apr 27, 2021 · 1 comment

Comments

@JoachimTuchel
Copy link

Sometimes I'd like to create a new instance of my recordClass with some additional initializations. Say I need to create a new empty address in a Customer Address on import. So I'd like the CSVREader not only to create a new instance by sending #new to the class, but something else.

I see two or three scenarios for this:

  • we add an inst var #creationMethod (with a default of #new)to NeoCSVReader and send that method to the #recordClass in #readNextRecordAsObject
    ex: myReader creationMethod: #newWithEmptyAddress
  • we add an inst var #postCreationMethod and send it to the newly created instance after its creation
  • we add some Block for this purpose

First question: does this make sense at all?
Second question: I have never used Pharo with Iceberg and git before and have no real idea hwo to do it, but if I wanted to, what version of Pharo and NeoCSVReader should I use these days? Pharo 8 or 9?

Here is what I think #readNextRecordAsObject would look like with this change:

``readNextRecordAsObject

| object conversionBlock idx |

conversionBlock := [:each :obj :input :fieldIndex |
	[each value: obj value: input]
		on: Error
		do: [:err |
			Error signal: (
				'Error parsing "%1" in column #%2: %3' bindWith: input with: fieldIndex asString with: err description)]].
				
object := recordClass perform: self instanceCreationMethod.  "<--- that's all, folks"
idx := 1.
fieldAccessors
	do: [:each | | rawValue |

...
``

@svenvc
Copy link
Owner

svenvc commented May 13, 2021

There is now the following commit:

0acc227

which should address a couple of issues.

There subclass hooks for instanciating recordClass.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants