mongoid_orderable 5.0.0 → 5.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +6 -0
- data/.rubocop_todo.yml +88 -0
- data/.travis.yml +26 -7
- data/CHANGELOG.md +45 -14
- data/CONTRIBUTING.md +118 -0
- data/Dangerfile +1 -0
- data/Gemfile +8 -4
- data/LICENSE.txt +20 -0
- data/README.md +6 -4
- data/RELEASING.md +68 -0
- data/Rakefile +19 -4
- data/lib/mongoid/orderable/callbacks.rb +26 -22
- data/lib/mongoid/orderable/configuration.rb +11 -13
- data/lib/mongoid/orderable/errors/invalid_target_position.rb +4 -7
- data/lib/mongoid/orderable/errors/mongoid_orderable_error.rb +0 -8
- data/lib/mongoid/orderable/generator/helpers.rb +2 -4
- data/lib/mongoid/orderable/generator/listable.rb +0 -2
- data/lib/mongoid/orderable/generator/movable.rb +8 -10
- data/lib/mongoid/orderable/generator/position.rb +0 -2
- data/lib/mongoid/orderable/generator/scope.rb +3 -3
- data/lib/mongoid/orderable/generator.rb +1 -2
- data/lib/mongoid/orderable/helpers.rb +25 -26
- data/lib/mongoid/orderable/listable.rb +13 -15
- data/lib/mongoid/orderable/movable.rb +6 -8
- data/lib/mongoid/orderable/orderable_class.rb +3 -7
- data/lib/mongoid/orderable.rb +1 -3
- data/lib/mongoid_orderable/version.rb +1 -1
- data/lib/mongoid_orderable.rb +6 -12
- data/mongoid_orderable.gemspec +15 -15
- data/spec/mongoid/orderable_spec.rb +279 -331
- data/spec/spec_helper.rb +5 -16
- metadata +11 -8
- data/lib/mongoid_orderable/mongoid/contexts/enumerable.rb +0 -15
- data/lib/mongoid_orderable/mongoid/contexts/mongo.rb +0 -18
- data/lib/mongoid_orderable/mongoid/criteria.rb +0 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7eaa2e05f5a3531b345dde5acd84bba859f71cc0
|
4
|
+
data.tar.gz: 8cbe732f1b5b60e66d9dad58a904e0157f8ef987
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 874989f19ae666bf7777379f45640686f457b101b5e04fdded8867c3403f7de79383b30448df6fdcbab491f0640dd5a73eb03e9a503568205a3bd4b00b050f3a
|
7
|
+
data.tar.gz: bacd372ac1644e959e668e1064fa771a3cae60c427c67f217ece8fdf5408cbc5d1d0ad97745e06905237deba44e30eb843c42527017f527a36cbd5ef3b0b5a9f
|
data/.rubocop.yml
ADDED
data/.rubocop_todo.yml
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
# This configuration was generated by
|
2
|
+
# `rubocop --auto-gen-config`
|
3
|
+
# on 2016-11-21 14:00:35 -0500 using RuboCop version 0.45.0.
|
4
|
+
# The point is for the user to remove these configuration records
|
5
|
+
# one by one as the offenses are removed from the code base.
|
6
|
+
# Note that changes in the inspected code, or installation of new
|
7
|
+
# versions of RuboCop, may require this file to be generated again.
|
8
|
+
|
9
|
+
# Offense count: 1
|
10
|
+
Lint/AmbiguousOperator:
|
11
|
+
Exclude:
|
12
|
+
- 'lib/mongoid_orderable/mongoid/contextual/memory.rb'
|
13
|
+
|
14
|
+
# Offense count: 3
|
15
|
+
Metrics/AbcSize:
|
16
|
+
Max: 34
|
17
|
+
|
18
|
+
# Offense count: 1
|
19
|
+
# Configuration parameters: CountComments.
|
20
|
+
Metrics/BlockLength:
|
21
|
+
Max: 51
|
22
|
+
|
23
|
+
# Offense count: 2
|
24
|
+
Metrics/CyclomaticComplexity:
|
25
|
+
Max: 10
|
26
|
+
|
27
|
+
# Offense count: 96
|
28
|
+
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives.
|
29
|
+
# URISchemes: http, https
|
30
|
+
Metrics/LineLength:
|
31
|
+
Max: 134
|
32
|
+
|
33
|
+
# Offense count: 6
|
34
|
+
# Configuration parameters: CountComments.
|
35
|
+
Metrics/MethodLength:
|
36
|
+
Max: 17
|
37
|
+
|
38
|
+
# Offense count: 1
|
39
|
+
Metrics/PerceivedComplexity:
|
40
|
+
Max: 10
|
41
|
+
|
42
|
+
# Offense count: 1
|
43
|
+
Style/AccessorMethodName:
|
44
|
+
Exclude:
|
45
|
+
- 'lib/mongoid/orderable/configuration.rb'
|
46
|
+
|
47
|
+
# Offense count: 3
|
48
|
+
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
49
|
+
# SupportedStyles: nested, compact
|
50
|
+
Style/ClassAndModuleChildren:
|
51
|
+
Exclude:
|
52
|
+
- 'lib/mongoid/orderable.rb'
|
53
|
+
- 'lib/mongoid/orderable/errors/invalid_target_position.rb'
|
54
|
+
- 'lib/mongoid/orderable/errors/mongoid_orderable_error.rb'
|
55
|
+
|
56
|
+
# Offense count: 17
|
57
|
+
Style/Documentation:
|
58
|
+
Exclude:
|
59
|
+
- 'spec/**/*'
|
60
|
+
- 'test/**/*'
|
61
|
+
- 'lib/mongoid/orderable.rb'
|
62
|
+
- 'lib/mongoid/orderable/callbacks.rb'
|
63
|
+
- 'lib/mongoid/orderable/configuration.rb'
|
64
|
+
- 'lib/mongoid/orderable/errors/invalid_target_position.rb'
|
65
|
+
- 'lib/mongoid/orderable/generator.rb'
|
66
|
+
- 'lib/mongoid/orderable/generator/helpers.rb'
|
67
|
+
- 'lib/mongoid/orderable/generator/listable.rb'
|
68
|
+
- 'lib/mongoid/orderable/generator/movable.rb'
|
69
|
+
- 'lib/mongoid/orderable/generator/position.rb'
|
70
|
+
- 'lib/mongoid/orderable/generator/scope.rb'
|
71
|
+
- 'lib/mongoid/orderable/helpers.rb'
|
72
|
+
- 'lib/mongoid/orderable/listable.rb'
|
73
|
+
- 'lib/mongoid/orderable/movable.rb'
|
74
|
+
- 'lib/mongoid/orderable/orderable_class.rb'
|
75
|
+
- 'lib/mongoid_orderable.rb'
|
76
|
+
|
77
|
+
# Offense count: 2
|
78
|
+
# Cop supports --auto-correct.
|
79
|
+
# Configuration parameters: AllowAsExpressionSeparator.
|
80
|
+
Style/Semicolon:
|
81
|
+
Exclude:
|
82
|
+
- 'spec/mongoid/orderable_spec.rb'
|
83
|
+
|
84
|
+
# Offense count: 37
|
85
|
+
# Configuration parameters: SupportedStyles.
|
86
|
+
# SupportedStyles: snake_case, normalcase, non_integer
|
87
|
+
Style/VariableNumber:
|
88
|
+
EnforcedStyle: normalcase
|
data/.travis.yml
CHANGED
@@ -1,14 +1,33 @@
|
|
1
|
+
sudo: false
|
2
|
+
|
3
|
+
language: ruby
|
4
|
+
|
5
|
+
cache: bundler
|
6
|
+
|
7
|
+
services: mongodb
|
8
|
+
|
1
9
|
rvm:
|
2
|
-
-
|
3
|
-
- 2.0.0
|
4
|
-
- 2.1
|
5
|
-
- 2.2
|
6
|
-
# - rbx
|
10
|
+
- 2.3.1
|
7
11
|
|
8
12
|
env:
|
9
|
-
- MONGOID_VERSION=2
|
10
13
|
- MONGOID_VERSION=3
|
11
14
|
- MONGOID_VERSION=4
|
12
15
|
- MONGOID_VERSION=5
|
16
|
+
- MONGOID_VERSION=HEAD
|
13
17
|
|
14
|
-
|
18
|
+
before_install:
|
19
|
+
- gem update bundler
|
20
|
+
|
21
|
+
before_script:
|
22
|
+
- bundle exec danger
|
23
|
+
|
24
|
+
addons:
|
25
|
+
apt:
|
26
|
+
sources:
|
27
|
+
- mongodb-3.2-precise
|
28
|
+
packages:
|
29
|
+
- mongodb-org-server
|
30
|
+
|
31
|
+
matrix:
|
32
|
+
allow_failures:
|
33
|
+
- env: MONGOID_VERSION=HEAD
|
data/CHANGELOG.md
CHANGED
@@ -1,22 +1,53 @@
|
|
1
|
-
|
1
|
+
### 5.1.0 (2017/06/04)
|
2
2
|
|
3
|
-
#
|
3
|
+
* [#50](https://github.com/mongoid/mongoid_orderable/pull/50): Added Danger, PR linter - [@dblock](https://github.com/dblock).
|
4
|
+
* [#51](https://github.com/mongoid/mongoid_orderable/pull/51): Added RuboCop - [@dblock](https://github.com/dblock).
|
5
|
+
* [#49](https://github.com/mongoid/mongoid_orderable/pull/49): Fix orderable on embedded documents inside an inherited model - [@rafaelgaspar](https://github.com/rafaelgaspar).
|
4
6
|
|
5
|
-
|
6
|
-
* Ruby 1.8 support dropped
|
7
|
+
### 5.0.0 (2015/10/21)
|
7
8
|
|
8
|
-
#
|
9
|
+
* [#41](https://github.com/mongoid/mongoid_orderable/pull/41): Mongoid 5 support - [@dblock](https://github.com/dblock).
|
10
|
+
* [#41](https://github.com/mongoid/mongoid_orderable/pull/41): Dropped support for ruby 1.8 - [@dblock](https://github.com/dblock).
|
9
11
|
|
10
|
-
|
12
|
+
### 4.1.1 (2014/12/19)
|
11
13
|
|
12
|
-
#
|
14
|
+
* [#34](https://github.com/mongoid/mongoid_orderable/pull/34): Fix: index should respect scope - [@joeyAghion](https://github.com/joeyAghion).
|
13
15
|
|
14
|
-
|
15
|
-
* Fix: relation metadata quering (@pjkelly)
|
16
|
-
* `previous_items` and `next_items` methods (@mrjlynch)
|
16
|
+
### 4.1.0 (2014/3/19)
|
17
17
|
|
18
|
-
#
|
18
|
+
* [#30](https://github.com/mongoid/mongoid_orderable/pull/30): Fix: reset a single column when `orderable_scope` changed instead of removing it from list - [@Bharat311](https://github.com/Bharat311).
|
19
|
+
* [#29](https://github.com/mongoid/mongoid_orderable/pull/29): Fix: incorrect position when orderable base is set - [@Bharat311](https://github.com/Bharat311).
|
20
|
+
* [#28](https://github.com/mongoid/mongoid_orderable/pull/28): Inherited `orderable_configurations` - [@johnny-miyake](https://github.com/johnny-miyake).
|
21
|
+
* [#27](https://github.com/mongoid/mongoid_orderable/pull/27): Allowed numeric string to specify a target position - [@johnny-miyake](https://github.com/johnny-miyake).
|
22
|
+
* [#26](https://github.com/mongoid/mongoid_orderable/pull/26): Added support for multiple orderable columns - [@Bharat311](https://github.com/Bharat311).
|
23
|
+
* [#22](https://github.com/mongoid/mongoid_orderable/pull/22): Added lazy support for scopes with different foreign key names - [@dsci](https://github.com/dsci).
|
24
|
+
* [#21](https://github.com/mongoid/mongoid_orderable/pull/21): Accounting for change in Mongoid's metadata API - [@pjkelly](https://github.com/pjkelly).
|
25
|
+
* [#20](https://github.com/mongoid/mongoid_orderable/pull/20): Added next and previous item methods - [@mrjlynch](https://github.com/mrjlynch).
|
26
|
+
* [#19](https://github.com/mongoid/mongoid_orderable/pull/19): Added lower and higher item methods - [@mrjlynch](https://github.com/mrjlynch).
|
19
27
|
|
20
|
-
|
21
|
-
|
22
|
-
|
28
|
+
### 4.0.0 (2013/10/22)
|
29
|
+
|
30
|
+
* [#18](https://github.com/mongoid/mongoid_orderable/pull/18): Added Mongoid 4 support - [@dblock](https://github.com/dblock).
|
31
|
+
* [#16](https://github.com/mongoid/mongoid_orderable/pull/16): Fix for Mongoid identity map combined with scoped orderable - [@johnnyshields](https://github.com/johnnyshields).
|
32
|
+
* [#15](https://github.com/mongoid/mongoid_orderable/pull/15): Support pass-thru of Mongoid field alias (`:as` parameter) - [@johnnyshields](https://github.com/johnnyshields).
|
33
|
+
* [#13](https://github.com/mongoid/mongoid_orderable/pull/13): Support inheritance - [@zhengjia](https://github.com/zhengjia).
|
34
|
+
|
35
|
+
### 1.2.0 (2013/1/10)
|
36
|
+
|
37
|
+
* [#12](https://github.com/mongoid/mongoid_orderable/pull/12): Added support for "base" in config options, in order to do a zero-based position - [@johnnyshields](https://github.com/johnnyshields).
|
38
|
+
|
39
|
+
### 1.1.0 (2012/5/23)
|
40
|
+
|
41
|
+
* Added Mongoid 3 support - [@pyromaniac](https://github.com/pyromaniac).
|
42
|
+
|
43
|
+
### 1.0.0 (2012/2/14)
|
44
|
+
|
45
|
+
* [#5](https://github.com/mongoid/mongoid_orderable/pull/5): Allow for use with default scopes - [@mattiassvedhem](https://github.com/mattiassvedhem).
|
46
|
+
|
47
|
+
### 0.9.1 (2012/2/3)
|
48
|
+
|
49
|
+
### 0.9.0 (2011/11/23)
|
50
|
+
|
51
|
+
### 0.0.1 (2011/11/1)
|
52
|
+
|
53
|
+
* Initial public release - [@pyromaniac](https://github.com/pyromaniac).
|
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
Contributing to Mongoid::Orderable
|
2
|
+
==================================
|
3
|
+
|
4
|
+
Mongoid::Orderable is work of [many of contributors](https://github.com/mongoid/mongoid_orderable/graphs/contributors). You're encouraged to submit [pull requests](https://github.com/mongoid/mongoid_orderable/pulls), [propose features, ask questions and discuss issues](https://github.com/mongoid/mongoid_orderable/issues).
|
5
|
+
|
6
|
+
#### Fork the Project
|
7
|
+
|
8
|
+
Fork the [project on Github](https://github.com/mongoid/mongoid_orderable) and check out your copy.
|
9
|
+
|
10
|
+
```
|
11
|
+
git clone https://github.com/contributor/mongoid_orderable.git
|
12
|
+
cd mongoid_orderable
|
13
|
+
git remote add upstream https://github.com/mongoid/mongoid_orderable.git
|
14
|
+
```
|
15
|
+
|
16
|
+
#### Create a Topic Branch
|
17
|
+
|
18
|
+
Make sure your fork is up-to-date and create a topic branch for your feature or bug fix.
|
19
|
+
|
20
|
+
```
|
21
|
+
git checkout master
|
22
|
+
git pull upstream master
|
23
|
+
git checkout -b my-feature-branch
|
24
|
+
```
|
25
|
+
|
26
|
+
#### Bundle Install and Test
|
27
|
+
|
28
|
+
Ensure that you can build the project and run tests.
|
29
|
+
|
30
|
+
```
|
31
|
+
bundle install
|
32
|
+
bundle exec rake
|
33
|
+
```
|
34
|
+
|
35
|
+
#### Write Tests
|
36
|
+
|
37
|
+
Try to write a test that reproduces the problem you're trying to fix or describes a feature that you want to build. Add to [spec/mongoid_orderable](spec/mongoid_orderable).
|
38
|
+
|
39
|
+
We definitely appreciate pull requests that highlight or reproduce a problem, even without a fix.
|
40
|
+
|
41
|
+
#### Write Code
|
42
|
+
|
43
|
+
Implement your feature or bug fix.
|
44
|
+
|
45
|
+
Ruby style is enforced with [Rubocop](https://github.com/bbatsov/rubocop), run `bundle exec rubocop` and fix any style issues highlighted.
|
46
|
+
|
47
|
+
Make sure that `bundle exec rake` completes without errors.
|
48
|
+
|
49
|
+
#### Write Documentation
|
50
|
+
|
51
|
+
Document any external behavior in the [README](README.md).
|
52
|
+
|
53
|
+
#### Update Changelog
|
54
|
+
|
55
|
+
Add a line to [CHANGELOG](CHANGELOG.md) under *Next Release*. Make it look like every other line, including your name and link to your Github account.
|
56
|
+
|
57
|
+
#### Commit Changes
|
58
|
+
|
59
|
+
Make sure git knows your name and email address:
|
60
|
+
|
61
|
+
```
|
62
|
+
git config --global user.name "Your Name"
|
63
|
+
git config --global user.email "contributor@example.com"
|
64
|
+
```
|
65
|
+
|
66
|
+
Writing good commit logs is important. A commit log should describe what changed and why.
|
67
|
+
|
68
|
+
```
|
69
|
+
git add ...
|
70
|
+
git commit
|
71
|
+
```
|
72
|
+
|
73
|
+
#### Push
|
74
|
+
|
75
|
+
```
|
76
|
+
git push origin my-feature-branch
|
77
|
+
```
|
78
|
+
|
79
|
+
#### Make a Pull Request
|
80
|
+
|
81
|
+
Go to https://github.com/contributor/mongoid_orderable and select your feature branch. Click the 'Pull Request' button and fill out the form. Pull requests are usually reviewed within a few days.
|
82
|
+
|
83
|
+
#### Rebase
|
84
|
+
|
85
|
+
If you've been working on a change for a while, rebase with upstream/master.
|
86
|
+
|
87
|
+
```
|
88
|
+
git fetch upstream
|
89
|
+
git rebase upstream/master
|
90
|
+
git push origin my-feature-branch -f
|
91
|
+
```
|
92
|
+
|
93
|
+
#### Update CHANGELOG Again
|
94
|
+
|
95
|
+
Update the [CHANGELOG](CHANGELOG.md) with the pull request number. A typical entry looks as follows.
|
96
|
+
|
97
|
+
```
|
98
|
+
* [#123](https://github.com/mongoid/mongoid_orderable/pull/123): Reticulated splines - [@contributor](https://github.com/contributor).
|
99
|
+
```
|
100
|
+
|
101
|
+
Amend your previous commit and force push the changes.
|
102
|
+
|
103
|
+
```
|
104
|
+
git commit --amend
|
105
|
+
git push origin my-feature-branch -f
|
106
|
+
```
|
107
|
+
|
108
|
+
#### Check on Your Pull Request
|
109
|
+
|
110
|
+
Go back to your pull request after a few minutes and see whether it passed muster with Travis-CI. Everything should look green, otherwise fix issues and amend your commit as described above.
|
111
|
+
|
112
|
+
#### Be Patient
|
113
|
+
|
114
|
+
It's likely that your change will not be merged and that the nitpicky maintainers will ask you to do more, or fix seemingly benign problems. Hang on there!
|
115
|
+
|
116
|
+
#### Thank You
|
117
|
+
|
118
|
+
Please do know that we really appreciate and value your time and work. We love you, really.
|
data/Dangerfile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
danger.import_dangerfile(gem: 'mongoid-danger')
|
data/Gemfile
CHANGED
@@ -1,18 +1,22 @@
|
|
1
|
-
source
|
1
|
+
source 'http://rubygems.org'
|
2
2
|
|
3
3
|
# Specify your gem's dependencies in mongoid_orderable.gemspec
|
4
4
|
gemspec
|
5
5
|
|
6
6
|
case version = ENV['MONGOID_VERSION'] || '5.0'
|
7
|
+
when 'HEAD'
|
8
|
+
gem 'mongoid', github: 'mongodb/mongoid'
|
7
9
|
when /^5/
|
8
10
|
gem 'mongoid', '~> 5.0'
|
9
11
|
when /^4/
|
10
12
|
gem 'mongoid', '~> 4.0'
|
11
13
|
when /^3/
|
12
14
|
gem 'mongoid', '~> 3.1'
|
13
|
-
when /^2/
|
14
|
-
gem 'mongoid', '~> 2.0'
|
15
|
-
gem 'bson_ext', platforms: :ruby
|
16
15
|
else
|
17
16
|
gem 'mongoid', version
|
18
17
|
end
|
18
|
+
|
19
|
+
group :test do
|
20
|
+
gem 'rubocop', '0.45.0'
|
21
|
+
gem 'mongoid-danger', '~> 0.1.0', require: false
|
22
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011-2016 Arkadiy Zabazhanov & Contributors
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
[![Gem Version](https://badge.fury.io/rb/mongoid_orderable.svg)](https://badge.fury.io/rb/mongoid_orderable)
|
2
|
-
[![Build Status](https://travis-ci.org/
|
2
|
+
[![Build Status](https://travis-ci.org/mongoid/mongoid_orderable.svg?branch=master)](https://travis-ci.org/mongoid/mongoid_orderable)
|
3
3
|
|
4
4
|
# What?
|
5
5
|
|
@@ -142,8 +142,10 @@ To ensure the position is written correctly, you will need to provide the cascad
|
|
142
142
|
|
143
143
|
# Contributing
|
144
144
|
|
145
|
-
|
145
|
+
See [CONTRIBUTING](CONTRIBUTING.md).
|
146
146
|
|
147
|
-
# License
|
147
|
+
# Copyright & License
|
148
148
|
|
149
|
-
|
149
|
+
Copyright (c) 2011-2016 Arkadiy Zabazhanov & Contributors.
|
150
|
+
|
151
|
+
MIT license, see [LICENSE](LICENSE.txt) for details.
|
data/RELEASING.md
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
Releasing Mongoid::Orderable
|
2
|
+
============================
|
3
|
+
|
4
|
+
There're no particular rules about when to release mongoid_orderable. Release bug fixes frequently, features not so frequently and breaking API changes rarely.
|
5
|
+
|
6
|
+
### Release
|
7
|
+
|
8
|
+
Run tests, check that all tests succeed locally.
|
9
|
+
|
10
|
+
```
|
11
|
+
bundle install
|
12
|
+
rake
|
13
|
+
```
|
14
|
+
|
15
|
+
Check that the last build succeeded in [Travis CI](https://travis-ci.org/mongoid/mongoid_orderable) for all supported platforms.
|
16
|
+
|
17
|
+
Increment the version, modify [lib/mongoid_orderable/version.rb](lib/mongoid_orderable/version.rb).
|
18
|
+
|
19
|
+
* Increment the third number if the release has bug fixes and/or very minor features, only (eg. change `0.5.1` to `0.5.2`).
|
20
|
+
* Increment the second number if the release contains major features or breaking API changes (eg. change `0.5.1` to `0.4.0`).
|
21
|
+
|
22
|
+
Change "Next Release" in [CHANGELOG.md](CHANGELOG.md) to the new version.
|
23
|
+
|
24
|
+
```
|
25
|
+
### 0.4.0 (2014-01-27)
|
26
|
+
```
|
27
|
+
|
28
|
+
Remove the line with "Your contribution here.", since there will be no more contributions to this release.
|
29
|
+
|
30
|
+
Commit your changes.
|
31
|
+
|
32
|
+
```
|
33
|
+
git add CHANGELOG.md lib/mongoid_orderable/version.rb
|
34
|
+
git commit -m "Preparing for release, 0.4.0."
|
35
|
+
git push origin master
|
36
|
+
```
|
37
|
+
|
38
|
+
Release.
|
39
|
+
|
40
|
+
```
|
41
|
+
$ rake release
|
42
|
+
|
43
|
+
mongoid_orderable 0.4.0 built to pkg/mongoid_orderable-0.4.0.gem.
|
44
|
+
Tagged v0.4.0.
|
45
|
+
Pushed git commits and tags.
|
46
|
+
Pushed mongoid_orderable 0.4.0 to rubygems.org.
|
47
|
+
```
|
48
|
+
|
49
|
+
### Prepare for the Next Version
|
50
|
+
|
51
|
+
Add the next release to [CHANGELOG.md](CHANGELOG.md).
|
52
|
+
|
53
|
+
```
|
54
|
+
Next Release
|
55
|
+
============
|
56
|
+
|
57
|
+
* Your contribution here.
|
58
|
+
```
|
59
|
+
|
60
|
+
Increment the minor version, modify [lib/mongoid_orderable/version.rb](lib/mongoid_orderable/version.rb).
|
61
|
+
|
62
|
+
Commit your changes.
|
63
|
+
|
64
|
+
```
|
65
|
+
git add CHANGELOG.md lib/mongoid_orderable/version.rb
|
66
|
+
git commit -m "Preparing for next release, 0.4.1."
|
67
|
+
git push origin master
|
68
|
+
```
|
data/Rakefile
CHANGED
@@ -1,6 +1,21 @@
|
|
1
|
-
require
|
2
|
-
|
1
|
+
require 'bundler'
|
2
|
+
begin
|
3
|
+
Bundler.setup(:default, :development)
|
4
|
+
rescue Bundler::BundlerError => e
|
5
|
+
$stderr.puts e.message
|
6
|
+
$stderr.puts 'Run `bundle install` to install missing gems'
|
7
|
+
exit e.status_code
|
8
|
+
end
|
3
9
|
|
4
|
-
|
10
|
+
Bundler::GemHelper.install_tasks
|
5
11
|
|
6
|
-
|
12
|
+
require 'rspec/core'
|
13
|
+
require 'rspec/core/rake_task'
|
14
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
15
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
16
|
+
end
|
17
|
+
|
18
|
+
require 'rubocop/rake_task'
|
19
|
+
RuboCop::RakeTask.new(:rubocop)
|
20
|
+
|
21
|
+
task default: [:rubocop, :spec]
|
@@ -4,64 +4,68 @@ module Mongoid
|
|
4
4
|
extend ActiveSupport::Concern
|
5
5
|
|
6
6
|
included do
|
7
|
-
|
8
7
|
protected
|
9
8
|
|
10
9
|
def add_to_list
|
11
|
-
|
10
|
+
orderable_keys.each do |column|
|
12
11
|
apply_position column, move_all[column]
|
13
12
|
end
|
14
13
|
end
|
15
14
|
|
16
15
|
def remove_from_list
|
17
|
-
|
16
|
+
orderable_keys.each do |column|
|
18
17
|
remove_position_from_list column
|
19
18
|
end
|
20
19
|
end
|
21
20
|
|
22
21
|
def remove_position_from_list(column)
|
23
|
-
col
|
22
|
+
col = orderable_column(column)
|
23
|
+
pos = orderable_position(column)
|
24
24
|
MongoidOrderable.inc orderable_scoped(column).where(col.gt => pos), col, -1
|
25
25
|
end
|
26
26
|
|
27
|
-
def apply_position
|
27
|
+
def apply_position(column, target_position)
|
28
28
|
if persisted? && !embedded? && orderable_scope_changed?(column)
|
29
29
|
self.class.unscoped.find(_id).remove_position_from_list(column)
|
30
|
-
|
30
|
+
send("orderable_#{column}_position=", nil)
|
31
31
|
end
|
32
32
|
|
33
33
|
return if !target_position && in_list?(column)
|
34
34
|
|
35
35
|
target_position = target_position_to_position column, target_position
|
36
|
-
scope
|
36
|
+
scope = orderable_scoped(column)
|
37
|
+
col = orderable_column(column)
|
38
|
+
pos = orderable_position(column)
|
37
39
|
|
38
|
-
|
40
|
+
if !in_list?(column)
|
39
41
|
MongoidOrderable.inc scope.where(col.gte => target_position), col, 1
|
40
|
-
|
41
|
-
MongoidOrderable.inc(scope.where(col.gte => target_position, col.lt => pos), col, 1)
|
42
|
-
|
42
|
+
elsif target_position < pos
|
43
|
+
MongoidOrderable.inc(scope.where(col.gte => target_position, col.lt => pos), col, 1)
|
44
|
+
elsif target_position > pos
|
45
|
+
MongoidOrderable.inc(scope.where(col.gt => pos, col.lte => target_position), col, -1)
|
43
46
|
end
|
44
47
|
|
45
|
-
|
48
|
+
send("orderable_#{column}_position=", target_position)
|
46
49
|
end
|
47
50
|
|
48
|
-
def target_position_to_position
|
51
|
+
def target_position_to_position(column, target_position)
|
49
52
|
target_position = :bottom unless target_position
|
50
53
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
54
|
+
unless target_position.is_a? Numeric
|
55
|
+
target_position = case target_position.to_s
|
56
|
+
when 'top' then orderable_base(column)
|
57
|
+
when 'bottom' then bottom_orderable_position(column)
|
58
|
+
when 'higher' then orderable_position(column).pred
|
59
|
+
when 'lower' then orderable_position(column).next
|
60
|
+
when /\A\d+\Z/ then target_position.to_i
|
61
|
+
else raise Mongoid::Orderable::Errors::InvalidTargetPosition, target_position
|
62
|
+
end
|
63
|
+
end
|
59
64
|
|
60
65
|
target_position = orderable_base(column) if target_position < orderable_base(column)
|
61
66
|
target_position = bottom_orderable_position(column) if target_position > bottom_orderable_position(column)
|
62
67
|
target_position
|
63
68
|
end
|
64
|
-
|
65
69
|
end
|
66
70
|
|
67
71
|
module ClassMethods
|
@@ -1,7 +1,6 @@
|
|
1
1
|
module Mongoid
|
2
2
|
module Orderable
|
3
3
|
class Configuration
|
4
|
-
|
5
4
|
CONFIG_OPTIONS = %w(column scope foreign_key inherited base index default).map(&:to_sym)
|
6
5
|
FIELD_OPTIONS = %w(as).map(&:to_sym)
|
7
6
|
VALID_OPTIONS = CONFIG_OPTIONS + FIELD_OPTIONS
|
@@ -16,11 +15,11 @@ module Mongoid
|
|
16
15
|
end
|
17
16
|
|
18
17
|
def default_configuration
|
19
|
-
{ :
|
20
|
-
:
|
21
|
-
:
|
22
|
-
:
|
23
|
-
:
|
18
|
+
{ column: :position,
|
19
|
+
index: true,
|
20
|
+
scope: nil,
|
21
|
+
base: 1,
|
22
|
+
field_opts: { type: Integer } }
|
24
23
|
end
|
25
24
|
|
26
25
|
def self.build(parent, options = {})
|
@@ -37,7 +36,7 @@ module Mongoid
|
|
37
36
|
|
38
37
|
def set_field_options
|
39
38
|
FIELD_OPTIONS.each do |key|
|
40
|
-
next unless options.
|
39
|
+
next unless options.key? key
|
41
40
|
@options[:field_opts][key] = options.delete(key)
|
42
41
|
end
|
43
42
|
end
|
@@ -45,16 +44,15 @@ module Mongoid
|
|
45
44
|
def set_orderable_scope
|
46
45
|
if options[:scope].is_a?(Symbol) && options[:scope].to_s !~ /_id$/
|
47
46
|
scope_relation = @orderable_class.relations[options[:scope].to_s]
|
48
|
-
if scope_relation
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
47
|
+
@options[:scope] = if scope_relation
|
48
|
+
scope_relation.key.to_sym
|
49
|
+
else
|
50
|
+
"#{options[:scope]}_id".to_sym
|
51
|
+
end
|
53
52
|
elsif options[:scope].is_a?(String)
|
54
53
|
@options[:scope] = options[:scope].to_sym
|
55
54
|
end
|
56
55
|
end
|
57
|
-
|
58
56
|
end
|
59
57
|
end
|
60
58
|
end
|