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

Fix issue with skip! and with cloning @config. #52

Closed
wants to merge 1 commit into from

Conversation

pnomolos
Copy link
Contributor

The after_build blocks are called both before a model is found and after (via set_attributes). This means if you fire skip! based on some logic that only applies after a model is found it will be called before. Calling something like skip! unless model.persisted? is a good example of this.

While fixing this, I also noticed that configuring an importer via the ImporterClass.new do { ... } syntax didn't properly clone the configuration, so things such as the configuration's after_build_blocks were all pointing to the same object. This fixes that by adapting some syntax from Virtus' Value Object code.

The `after_build` blocks are called both before a model is found and after (via `set_attributes`).  This means if you fire `skip!` based on some logic that only applies after a model is found it will be called before.  Calling something like `skip! unless model.persisted?` is a good example of this.

While fixing this, I also noticed that configuring an importer via the `ImporterClass.new do { ... }` syntax didn't properly clone the configuration, so things such as the configuration's `after_build_blocks` were all pointing to the same object.  This fixes that by adapting some syntax from Virtus' Value Object code.
@pcreux
Copy link
Owner

pcreux commented Jan 5, 2017

That's great! Thank you @pnomolos!

pcreux pushed a commit that referenced this pull request Jan 6, 2017
The `after_build` blocks are called both before a model is found and
after (via `set_attributes`).  This means if you fire `skip!` based on
some logic that only applies after a model is found it will be called
before.  Calling something like `skip! unless model.persisted?` is a
good example of this.

Extracted from: #52
@pcreux
Copy link
Owner

pcreux commented Jan 6, 2017

Merged to master as 9aa01fa

@pcreux pcreux closed this Jan 6, 2017
artur-bobrushko pushed a commit to artur-bobrushko/Rails-CSV-importer that referenced this pull request Apr 27, 2019
The `after_build` blocks are called both before a model is found and
after (via `set_attributes`).  This means if you fire `skip!` based on
some logic that only applies after a model is found it will be called
before.  Calling something like `skip! unless model.persisted?` is a
good example of this.

Extracted from: pcreux/csv-importer#52
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

Successfully merging this pull request may close these issues.

2 participants