acts_as_list 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/FUNDING.yml +3 -0
- data/CHANGELOG.md +361 -352
- data/README.md +24 -3
- data/Rakefile +1 -1
- data/acts_as_list.gemspec +4 -4
- data/lib/acts_as_list/active_record/acts/list.rb +5 -1
- data/lib/acts_as_list/version.rb +1 -1
- data/test/test_list.rb +5 -0
- metadata +8 -8
data/README.md
CHANGED
@@ -12,8 +12,8 @@ This `acts_as` extension provides the capabilities for sorting and reordering a
|
|
12
12
|
|
13
13
|
There are a couple of changes of behaviour from `0.8.0` onwards:
|
14
14
|
|
15
|
-
- If you specify `add_new_at: :top`, new items will be added to the top of the list like always. But now, if you specify a position at insert time: `.create(position: 3)`, the position will be respected. In this example, the item will end up at position `3` and will move other items further down the list. Before `0.8.0` the position would be ignored and the item would still be added to the top of the list. [#220](https://github.com/
|
16
|
-
- `acts_as_list` now copes with disparate position integers (i.e. gaps between the numbers). There has been a change in behaviour for the `higher_items` method. It now returns items with the first item in the collection being the closest item to the reference item, and the last item in the collection being the furthest from the reference item (a.k.a. the first item in the list). [#223](https://github.com/
|
15
|
+
- If you specify `add_new_at: :top`, new items will be added to the top of the list like always. But now, if you specify a position at insert time: `.create(position: 3)`, the position will be respected. In this example, the item will end up at position `3` and will move other items further down the list. Before `0.8.0` the position would be ignored and the item would still be added to the top of the list. [#220](https://github.com/brendon/acts_as_list/pull/220)
|
16
|
+
- `acts_as_list` now copes with disparate position integers (i.e. gaps between the numbers). There has been a change in behaviour for the `higher_items` method. It now returns items with the first item in the collection being the closest item to the reference item, and the last item in the collection being the furthest from the reference item (a.k.a. the first item in the list). [#223](https://github.com/brendon/acts_as_list/pull/223)
|
17
17
|
|
18
18
|
## Installation
|
19
19
|
|
@@ -105,6 +105,25 @@ TodoList.all.each do |todo_list|
|
|
105
105
|
end
|
106
106
|
```
|
107
107
|
|
108
|
+
When using PostgreSQL, it is also possible to leave this migration up to the database layer. Inside of the `change` block you could write:
|
109
|
+
|
110
|
+
```ruby
|
111
|
+
execute <<~SQL.squeeze
|
112
|
+
UPDATE todo_items
|
113
|
+
SET position = mapping.new_position
|
114
|
+
FROM (
|
115
|
+
SELECT
|
116
|
+
id,
|
117
|
+
ROW_NUMBER() OVER (
|
118
|
+
PARTITION BY todo_list_id
|
119
|
+
ORDER BY updated_at
|
120
|
+
) as new_position
|
121
|
+
FROM todo_items
|
122
|
+
) AS mapping
|
123
|
+
WHERE todo_items.id = mapping.id;
|
124
|
+
SQL
|
125
|
+
```
|
126
|
+
|
108
127
|
## Notes
|
109
128
|
All `position` queries (select, update, etc.) inside gem methods are executed without the default scope (i.e. `Model.unscoped`), this will prevent nasty issues when the default scope is different from `acts_as_list` scope.
|
110
129
|
|
@@ -144,6 +163,8 @@ default: `1`. Use this option to define the top of the list. Use 0 to make the c
|
|
144
163
|
default: `:bottom`. Use this option to specify whether objects get added to the `:top` or `:bottom` of the list. `nil` will result in new items not being added to the list on create, i.e, position will be kept nil after create.
|
145
164
|
- `touch_on_update`
|
146
165
|
default: `true`. Use `touch_on_update: false` if you don't want to update the timestamps of the associated records.
|
166
|
+
- `sequential_updates`
|
167
|
+
Specifies whether insert_at should update objects positions during shuffling one by one to respect position column unique not null constraint. Defaults to true if position column has unique index, otherwise false. If constraint is `deferrable initially deferred` (PostgreSQL), overriding it with false will speed up insert_at.
|
147
168
|
|
148
169
|
## Disabling temporarily
|
149
170
|
|
@@ -251,7 +272,7 @@ end
|
|
251
272
|
```
|
252
273
|
|
253
274
|
## Versions
|
254
|
-
Version `0.9.0` adds `acts_as_list_no_update` (https://github.com/
|
275
|
+
Version `0.9.0` adds `acts_as_list_no_update` (https://github.com/brendon/acts_as_list/pull/244) and compatibility with not-null and uniqueness constraints on the database (https://github.com/brendon/acts_as_list/pull/246). These additions shouldn't break compatibility with existing implementations.
|
255
276
|
|
256
277
|
As of version `0.7.5` Rails 5 is supported.
|
257
278
|
|
data/Rakefile
CHANGED
data/acts_as_list.gemspec
CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |s|
|
|
9
9
|
s.platform = Gem::Platform::RUBY
|
10
10
|
s.authors = ["Swanand Pagnis", "Brendon Muir"]
|
11
11
|
s.email = %w(swanand.pagnis@gmail.com brendon@spikeatschool.co.nz)
|
12
|
-
s.homepage = "http://github.com/
|
12
|
+
s.homepage = "http://github.com/brendon/acts_as_list"
|
13
13
|
s.summary = "A gem adding sorting, reordering capabilities to an active_record model, allowing it to act as a list"
|
14
14
|
s.description = 'This "acts_as" extension provides the capabilities for sorting and reordering a number of objects in a list. The class that has this specified needs to have a "position" column defined as an integer on the mapped database table.'
|
15
15
|
s.license = "MIT"
|
@@ -17,9 +17,9 @@ Gem::Specification.new do |s|
|
|
17
17
|
s.required_ruby_version = ">= 2.4.7"
|
18
18
|
|
19
19
|
if s.respond_to?(:metadata)
|
20
|
-
s.metadata['changelog_uri'] = 'https://github.com/
|
21
|
-
s.metadata['source_code_uri'] = 'https://github.com/
|
22
|
-
s.metadata['bug_tracker_uri'] = 'https://github.com/
|
20
|
+
s.metadata['changelog_uri'] = 'https://github.com/brendon/acts_as_list/blob/master/CHANGELOG.md'
|
21
|
+
s.metadata['source_code_uri'] = 'https://github.com/brendon/acts_as_list'
|
22
|
+
s.metadata['bug_tracker_uri'] = 'https://github.com/brendon/acts_as_list/issues'
|
23
23
|
end
|
24
24
|
|
25
25
|
# Load Paths...
|
@@ -312,7 +312,11 @@ module ActiveRecord
|
|
312
312
|
scope = scope.where("#{quoted_table_name}.#{self.class.primary_key} != ?", avoid_id)
|
313
313
|
end
|
314
314
|
|
315
|
-
|
315
|
+
if sequential_updates?
|
316
|
+
scope.where("#{quoted_position_column_with_table_name} >= ?", position).reorder(acts_as_list_order_argument(:desc)).increment_sequentially
|
317
|
+
else
|
318
|
+
scope.where("#{quoted_position_column_with_table_name} >= ?", position).increment_all
|
319
|
+
end
|
316
320
|
end
|
317
321
|
|
318
322
|
# This has the effect of moving all the higher items up one.
|
data/lib/acts_as_list/version.rb
CHANGED
data/test/test_list.rb
CHANGED
@@ -995,6 +995,11 @@ class SequentialUpdatesMixinNotNullUniquePositiveConstraintsTest < ActsAsListTes
|
|
995
995
|
assert_equal 3, new.pos
|
996
996
|
end
|
997
997
|
|
998
|
+
def test_create_at_top
|
999
|
+
new = SequentialUpdatesAltId.create!(pos: 1)
|
1000
|
+
assert_equal 1, new.pos
|
1001
|
+
end
|
1002
|
+
|
998
1003
|
def test_move_to_bottom
|
999
1004
|
item = SequentialUpdatesAltId.order(:pos).first
|
1000
1005
|
item.move_to_bottom
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: acts_as_list
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Swanand Pagnis
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2020-02-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|
@@ -50,6 +50,7 @@ extensions: []
|
|
50
50
|
extra_rdoc_files: []
|
51
51
|
files:
|
52
52
|
- ".gemtest"
|
53
|
+
- ".github/FUNDING.yml"
|
53
54
|
- ".gitignore"
|
54
55
|
- ".travis.yml"
|
55
56
|
- Appraisals
|
@@ -93,13 +94,13 @@ files:
|
|
93
94
|
- test/test_no_update_for_extra_classes.rb
|
94
95
|
- test/test_no_update_for_scope_destruction.rb
|
95
96
|
- test/test_no_update_for_subclasses.rb
|
96
|
-
homepage: http://github.com/
|
97
|
+
homepage: http://github.com/brendon/acts_as_list
|
97
98
|
licenses:
|
98
99
|
- MIT
|
99
100
|
metadata:
|
100
|
-
changelog_uri: https://github.com/
|
101
|
-
source_code_uri: https://github.com/
|
102
|
-
bug_tracker_uri: https://github.com/
|
101
|
+
changelog_uri: https://github.com/brendon/acts_as_list/blob/master/CHANGELOG.md
|
102
|
+
source_code_uri: https://github.com/brendon/acts_as_list
|
103
|
+
bug_tracker_uri: https://github.com/brendon/acts_as_list/issues
|
103
104
|
post_install_message:
|
104
105
|
rdoc_options: []
|
105
106
|
require_paths:
|
@@ -115,8 +116,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
115
116
|
- !ruby/object:Gem::Version
|
116
117
|
version: '0'
|
117
118
|
requirements: []
|
118
|
-
|
119
|
-
rubygems_version: 2.7.6.2
|
119
|
+
rubygems_version: 3.0.3
|
120
120
|
signing_key:
|
121
121
|
specification_version: 4
|
122
122
|
summary: A gem adding sorting, reordering capabilities to an active_record model,
|