magnusvk/counter_culture — pull request #43 by cirosantilli (2014-01-28 21:14:58+00:00)
Title: added delta by arbritary proc option

Fixes #38

What this does is well explained on the issue it closes, and on the new README section.

I feel it is logical to call the new option simply `:delta`, since it is analogous to `delta_column` but it does not deal with an specific column.

If anyone has a better name, please shoot.

**_update_counts_after_XXX**

Changes to the three `_update_counts_after_*` functions were trivial and should be easy to evaluate.

**counter_culture_fix_counts**

`counter_culture_fix_counts` was much less trivial and required some refactoring to keep things DRY.

Non `:delta` logic should still be intact.

- moved many method calls that do not depend on loop variables to outside of the loops

- moved all input validity and default value check to the very beginning of the method

- moved the final check logic into `fix_counts` private function

- renamed overly general variable names to make things easier to understand:

- `records` => `records_to_fix`
- `counts` => `updated_counts`

- used `find_in_batches` wherever possible, since it replaces at once `offset`, `limit` and the loop variable.

- made some comments on critical parts which were hard for me to understand

**tests**

All existing tests pass.

Added one `:delta` test for every existing `:delta_column` test.

Added a new test specific to `:delta` to check that sums are being made correctly across batches.

Put all functions that test `counter_culture_fix_counts` side by side.

**other changes**

Corrected a typo on a test name: "flaot" => "float".

Removed randomly placed trailing whitespaces.