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

Added support for "base" in config options, in order to do a zero-based position #12

Merged
merged 3 commits into from
Jan 10, 2013
Merged

Conversation

johnnyshields
Copy link
Member

Added support for "base" in config options, in order to do a zero-based position. The reason for this is that Ruby, MongoDB, and Javascript all use zero-based arrays as a standard, so in my app I found I was doing a lot of -1 when reading / +1 when writing.

The default config value is 1, which keeps current behavior intact.

There is an added public accessor "orderable_base" to get this attribute.

Have added appropriate Rspec tests.

Have also bumped minor version. According to sem-ver it's an API change but does not break the existing API or change existing behavior.

Lastly, please look at the change to "bottom_orderable_position" method and confirm it is suitable. I believe are the ".map(&:to_i).max" part are Ruby array methods, not a mongo instruction, so it should not affect performance.

…ed position. The default is 1, which keeps current behavior intact.

There is an added public accessor "orderable_base" to get this attribute.

Have added appropriate Rspec tests.

Have also bumped minor version. According to sem-ver it's an API change but does not break the existing API or change existing behavior.

Lastly, please look at the change to "bottom_orderable_position" method and confirm it is suitable. I believe are the ".map(&:to_i).max" part are Ruby array methods, not a mongo instruction, so it should affect performance.
@johnnyshields
Copy link
Member Author

This should be good to merge.

Looks like the only Travis failing is Ruby 1.9.2 + MONGOID_VERSION='~> 3.0.0.rc', which should be deleted since I believe Mongoid 3 requires Ruby >= 1.9.3

@johnnyshields
Copy link
Member Author

Et voila. Travis is green.

pyromaniac added a commit that referenced this pull request Jan 10, 2013
Added support for "base" in config options, in order to do a zero-based position
@pyromaniac pyromaniac merged commit 67741d2 into mongoid:master Jan 10, 2013
@pyromaniac
Copy link
Collaborator

Perfect, thanks!

@johnnyshields
Copy link
Member Author

Cheers!!

@johnnyshields
Copy link
Member Author

Oh, d'oh forgot to add readme. Please add in this line:

  # orderable :base => 0 # count position from zero as the top-most value (1 is the default value)

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