Skip to content

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

Merged
pyromaniac merged 3 commits intomongoid:masterfrom
johnnyshields:master
Jan 10, 2013
Merged

Added support for "base" in config options, in order to do a zero-based position#12
pyromaniac merged 3 commits intomongoid:masterfrom
johnnyshields:master

Conversation

@johnnyshields
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Collaborator

Perfect, thanks!

@johnnyshields
Copy link
Copy Markdown
Member Author

Cheers!!

@johnnyshields
Copy link
Copy Markdown
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