activesorting 0.8.2 → 0.8.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +8 -8
- data/lib/active_sorting.rb +1 -0
- data/lib/active_sorting/exceptions.rb +10 -0
- data/lib/active_sorting/model.rb +4 -7
- data/lib/active_sorting/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 110ed0708191a4a732844a44f1e11f504f1e185f
|
4
|
+
data.tar.gz: 28df62623fc3ea6d226af72fa5d36b1baecc72a7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4f69fb55fdea5b43b4881204391c63212243afca83059cb7c5bbc17e8d913fcd9b4176994477bd1cf5e79942074978ee95bf9f054dea509897fe622a791576c4
|
7
|
+
data.tar.gz: 63e1f091a498c8155d33618a5c6da7e9a96dbacb6dcd69e3a2773dc0842f528ad8926cb64ee04a3f1b89743a6457cf591133a6451adfb8dcb76404f91122d47c
|
data/README.md
CHANGED
@@ -3,17 +3,17 @@
|
|
3
3
|
## Status
|
4
4
|
|
5
5
|
[](http://rubygems.org/gems/activesorting)
|
6
|
-
[](https://travis-ci.org/eventtus/active_sorting)
|
7
|
+
[](https://codeclimate.com/github/eventtus/active_sorting)
|
8
|
+
[](https://coveralls.io/github/eventtus/active_sorting?branch=master)
|
9
|
+
[](http://inch-ci.org/github/eventtus/active_sorting)
|
10
|
+
[](https://hakiri.io/github/owahab/active_sorting/master)
|
11
|
+
[](https://github.com/eventtus/active_sorting/issues)
|
11
12
|
[](http://rubygems.org/gems/activesorting)
|
12
|
-
[](https://github.com/owahab/active_sorting/issues)
|
13
13
|
|
14
14
|
Allows sorting Rails models using a custom field.
|
15
15
|
|
16
|
-
[Code Documentation](http://www.rubydoc.info/github/
|
16
|
+
[Code Documentation](http://www.rubydoc.info/github/eventtus/active_sorting)
|
17
17
|
|
18
18
|
## Requirements
|
19
19
|
|
@@ -70,6 +70,6 @@ Please see CONTRIBUTING.md for details.
|
|
70
70
|
|
71
71
|
## Credits
|
72
72
|
|
73
|
-
[](http://eventtus.com)
|
74
74
|
|
75
75
|
Project is sponsored by [Eventtus](http://eventtus.com).
|
data/lib/active_sorting.rb
CHANGED
data/lib/active_sorting/model.rb
CHANGED
@@ -31,11 +31,10 @@ module ActiveSorting
|
|
31
31
|
# +id_column+ the field used for fetching records from the databse,
|
32
32
|
# defaults to :id
|
33
33
|
def sort_list(new_list, id_column = :id)
|
34
|
-
raise ArgumentError, "Sortable list should not be empty"
|
35
|
-
conditions = {}
|
36
|
-
conditions[id_column] = new_list
|
34
|
+
raise ArgumentError, "Sortable list should not be empty" if new_list.empty?
|
35
|
+
conditions = { id_column => new_list }
|
37
36
|
old_list = unscoped.active_sorting_default_scope.where(conditions).pluck(id_column)
|
38
|
-
raise
|
37
|
+
raise Exceptions::RecordsNotFound, "Sortable list should be persisted to database with #{name} Model" if old_list.empty?
|
39
38
|
changes = active_sorting_changes_required(old_list, new_list)
|
40
39
|
active_sorting_make_changes(old_list, new_list, changes, id_column)
|
41
40
|
end
|
@@ -75,10 +74,8 @@ module ActiveSorting
|
|
75
74
|
# by comparing two proposals from
|
76
75
|
# +active_sorting_calculate_changes+
|
77
76
|
def active_sorting_changes_required(old_list, new_list)
|
77
|
+
raise Exceptions::InvalidListSize, "Sortable new and old lists should be of the same length" if old_list.count != new_list.count
|
78
78
|
changes = []
|
79
|
-
if old_list.count != new_list.count
|
80
|
-
raise ArgumentError, "Sortable new and old lists should be of the same length"
|
81
|
-
end
|
82
79
|
proposal1 = active_sorting_calculate_changes(old_list.dup, new_list.dup)
|
83
80
|
if proposal1.count >= (new_list.count / 4)
|
84
81
|
proposal2 = active_sorting_calculate_changes(old_list.dup.reverse, new_list.dup.reverse)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activesorting
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Omar Abdel-Wahab
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-10-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -167,6 +167,7 @@ files:
|
|
167
167
|
- gemfiles/50.gemfile.lock
|
168
168
|
- lib/active_sorting.rb
|
169
169
|
- lib/active_sorting/engine.rb
|
170
|
+
- lib/active_sorting/exceptions.rb
|
170
171
|
- lib/active_sorting/model.rb
|
171
172
|
- lib/active_sorting/version.rb
|
172
173
|
- lib/activesorting.rb
|
@@ -190,7 +191,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
190
191
|
version: '0'
|
191
192
|
requirements: []
|
192
193
|
rubyforge_project:
|
193
|
-
rubygems_version: 2.4.
|
194
|
+
rubygems_version: 2.4.8
|
194
195
|
signing_key:
|
195
196
|
specification_version: 4
|
196
197
|
summary: Adds ability to sort models using a custom field
|