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

add preprocess option to find_in_batches in ActiveRecord adapter #152

Closed
wants to merge 5 commits into from

Conversation

barelyknown
Copy link
Contributor

The need to have a preprocessor was mentioned in this issue => #151

This pull request adds support for a :preprocess option for __find_in_batches that enables the user to specify a method to use to preprocess the batch.

The test isn't exactly great, but it does ensure that the preprocessor is getting called when it's defined in the options.

I can add documentation if you're good to merge this.

@karmi
Copy link
Contributor

karmi commented Jun 24, 2014

I think this makes sense! Can you rename the option to transport, since a similar option for import is called like that (see #113, source)?

@barelyknown
Copy link
Contributor Author

Sure - I'd be happy to rename it. Given that transform operates at the instance level, maybe batch_transform is the right name for the method? That makes it most obvious in my opinion.

@karmi
Copy link
Contributor

karmi commented Jun 25, 2014

I think :transform would be fine... Can you add some realistic usage examples (preferably as docs, see eg. docs for import)? I would like to see an integration test for this as well, mainly as a way of documenting the feature.

@barelyknown
Copy link
Contributor Author

Sure, I'll add documentation and an integration test. About the name, it can't be transform because that is already used. The options that get passed to import get passed through to __find_in_batches so the name can't be the same.

@karmi
Copy link
Contributor

karmi commented Jun 25, 2014

OK, got it. Then the preprocess name is of course much better.


BTW, one way how to work with the codebase in this case would be something like:

Article.__elasticsearch__.class_eval do
  def __find_in_batches(*args)
    [] # Do whatever here...
  end  
end 

All the other models would still have the default __find_in_batches implementation.

@barelyknown
Copy link
Contributor Author

Documentation added plus a more descriptive test. Hopefully that looks good.

@karmi
Copy link
Contributor

karmi commented Jul 26, 2014

@barelyknown I'm sorry for letting this brew for such a long time... I'll try to have a look at it next week. Thanks!

@karmi karmi closed this in 9339bf7 Jul 28, 2014
karmi added a commit that referenced this pull request Jul 28, 2014
@karmi
Copy link
Contributor

karmi commented Jul 28, 2014

@barelyknown I've retouched the code, tests and examples a bit in 351e3b7, thanks for the patch!, it's a useful feature.

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

Successfully merging this pull request may close these issues.

2 participants