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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c24c8e9fbc1fecc4dc1e2e96d8c0580ceb5eab7f
4
- data.tar.gz: a043f97b256be42f1b73a86068a804af1177030c
3
+ metadata.gz: 110ed0708191a4a732844a44f1e11f504f1e185f
4
+ data.tar.gz: 28df62623fc3ea6d226af72fa5d36b1baecc72a7
5
5
  SHA512:
6
- metadata.gz: ba29eb87ce28ba1b4b70543b89acb16677be1a1e71f93e2b2f449b879624d8cb073a516af34eaa86c61893bbb06d28c59caa6a0517c87c3da9e8f766113e3d59
7
- data.tar.gz: f5f2b3adce2f2282d1615e560759651274a1b45ff525dc5071802de13085dc5ad8f7d4b5d27c04a6142ab2593537baf1f45bab6fd053123f3f5f19b6d1294dfa
6
+ metadata.gz: 4f69fb55fdea5b43b4881204391c63212243afca83059cb7c5bbc17e8d913fcd9b4176994477bd1cf5e79942074978ee95bf9f054dea509897fe622a791576c4
7
+ data.tar.gz: 63e1f091a498c8155d33618a5c6da7e9a96dbacb6dcd69e3a2773dc0842f528ad8926cb64ee04a3f1b89743a6457cf591133a6451adfb8dcb76404f91122d47c
data/README.md CHANGED
@@ -3,17 +3,17 @@
3
3
  ## Status
4
4
 
5
5
  [![Gem Version](https://img.shields.io/gem/v/activesorting.svg)](http://rubygems.org/gems/activesorting)
6
- [![Build Status](https://travis-ci.org/owahab/active_sorting.svg?branch=master)](https://travis-ci.org/owahab/active_sorting)
7
- [![Coverage Status](https://coveralls.io/repos/github/owahab/active_sorting/badge.svg?branch=master)](https://coveralls.io/github/owahab/active_sorting?branch=master)
8
- [![Code Climate](https://codeclimate.com/github/owahab/active_sorting/badges/gpa.svg)](https://codeclimate.com/github/owahab/active_sorting)
9
- [![Inline docs](http://inch-ci.org/github/owahab/active_sorting.svg?branch=master)](http://inch-ci.org/github/owahab/active_sorting)
10
- [![security](https://hakiri.io/github/owahab/active_sorting/master.svg)](https://hakiri.io/github/owahab/active_sorting/master)
6
+ [![Build Status](https://travis-ci.org/eventtus/active_sorting.svg?branch=master)](https://travis-ci.org/eventtus/active_sorting)
7
+ [![Code Climate](https://codeclimate.com/github/eventtus/active_sorting/badges/gpa.svg)](https://codeclimate.com/github/eventtus/active_sorting)
8
+ [![Coverage Status](https://coveralls.io/repos/github/eventtus/active_sorting/badge.svg?branch=master)](https://coveralls.io/github/eventtus/active_sorting?branch=master)
9
+ [![Inline docs](http://inch-ci.org/github/eventtus/active_sorting.svg?branch=master)](http://inch-ci.org/github/eventtus/active_sorting)
10
+ [![security](https://hakiri.io/github/eventtus/active_sorting/master.svg)](https://hakiri.io/github/owahab/active_sorting/master)
11
+ [![GitHub issues](https://img.shields.io/github/issues/eventtus/active_sorting.svg?maxAge=2592000)](https://github.com/eventtus/active_sorting/issues)
11
12
  [![Downloads](https://img.shields.io/gem/dtv/activesorting.svg)](http://rubygems.org/gems/activesorting)
12
- [![GitHub issues](https://img.shields.io/github/issues/owahab/active_sorting.svg?maxAge=2592000)](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/owahab/active_sorting)
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
- [![Eventtus](http://eventtus.com/css/images/logo.png)](http://eventtus.com)
73
+ [![Eventtus](http://assets.eventtus.com/logos/eventtus/standard.png)](http://eventtus.com)
74
74
 
75
75
  Project is sponsored by [Eventtus](http://eventtus.com).
@@ -1,4 +1,5 @@
1
1
  require 'rails/engine'
2
2
  require 'active_record'
3
3
  require 'active_sorting/version'
4
+ require 'active_sorting/exceptions'
4
5
  require 'active_sorting/engine'
@@ -0,0 +1,10 @@
1
+ module ActiveSorting
2
+ module Exceptions
3
+ class RecordsNotFound < StandardError
4
+ end
5
+
6
+ class InvalidListSize < StandardError
7
+ end
8
+ end
9
+ end
10
+
@@ -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" unless new_list.count
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 ArgumentError, "Sortable list should be persisted to database" unless old_list.count
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)
@@ -1,3 +1,3 @@
1
1
  module ActiveSorting
2
- VERSION = '0.8.2'.freeze
2
+ VERSION = '0.8.3'.freeze
3
3
  end
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.2
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: 2016-07-12 00:00:00.000000000 Z
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.5
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