positioning 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -1
- data/README.md +31 -0
- data/lib/positioning/version.rb +1 -1
- data/lib/positioning.rb +11 -7
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a486284bed84d9458dfc46093bf97d94f56e808de40843bffbc5cdacde4606b3
|
4
|
+
data.tar.gz: f31839ad358b3db74b55596dda9c77ce32a8a661923dc257962ac36deb7520c7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 54a7ea806656b3cab3b32846dfb365b9107389d83ac37fed41b145a3daa82917ce27c2f7765713e6440d6571d4b735d9a958713e65c61879244378b9c6f1511e
|
7
|
+
data.tar.gz: 85af57db02799e96fddb74f9a14debaa1a0e0d2ff06144f41c50be9d5bd9c66d103fbd1cefc86a9c0e9061e3f172c37015eee078440b418da055bd4c67075c97
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
+
## [0.2.3] - 2024-07-06
|
4
|
+
|
5
|
+
- Advisory Lock can now be optionally turned off via `advisory_lock: false` on your `positioned` call. See the README for more details. Advisory Lock remains on by default. Thanks @joaomarcos96!
|
6
|
+
|
3
7
|
## [0.2.2] - 2024-05-17
|
4
8
|
|
5
9
|
- When destroying a positioned item, first move it out of the way (position = 0) then contract the scope. Do this before destruction. Moving the item out of the way memoizes its original position to cope with the case where multiple items are destroyed with `destroy_all` as they'll have their position column cached. Thanks @james-reading for the report.
|
@@ -16,7 +20,7 @@
|
|
16
20
|
|
17
21
|
## [0.1.7] - 2024-03-06
|
18
22
|
|
19
|
-
-
|
23
|
+
- Separated the Concern that is included into ActiveRecord::Base into its own submodule so that Mechanisms isn't also included.
|
20
24
|
- Added the RelativePosition Struct and documentation to make it easier to supply relative positions via form helpers.
|
21
25
|
|
22
26
|
## [0.1.6] - 2024-03-05
|
data/README.md
CHANGED
@@ -66,6 +66,10 @@ positioned on: :type
|
|
66
66
|
belongs_to :list
|
67
67
|
belongs_to :category
|
68
68
|
positioned on: [:list, :category, :enabled]
|
69
|
+
|
70
|
+
# If you do not want to use Advisory Lock, you can disable it entirely by passing the 'advisory_lock' flag as false
|
71
|
+
belongs_to :list
|
72
|
+
positioned on: :list, advisory_lock: false
|
69
73
|
```
|
70
74
|
|
71
75
|
### Manipulating Positioning
|
@@ -243,6 +247,33 @@ https://github.com/brendon/positioning/blob/main/lib/positioning/advisory_lock.r
|
|
243
247
|
|
244
248
|
If you have any concerns or improvements please file a GitHub issue.
|
245
249
|
|
250
|
+
### Opting out of Advisory Lock
|
251
|
+
|
252
|
+
There are cases where Advisory Lock may be unwanted or unnecessary, for instance, if you already lock the parent record in **every** operation that will touch the database on the positioned item, **everywhere** in your application.
|
253
|
+
|
254
|
+
Example of such scenario in your application:
|
255
|
+
|
256
|
+
```ruby
|
257
|
+
list = List.create(name: "List")
|
258
|
+
|
259
|
+
list.with_lock do
|
260
|
+
item_a = list.items.create(name: "Item A")
|
261
|
+
item_b = list.items.create(name: "Item B")
|
262
|
+
item_c = list.items.create(name: "Item C")
|
263
|
+
|
264
|
+
item_c.update(position: {before: item_a})
|
265
|
+
|
266
|
+
item_a.destroy
|
267
|
+
end
|
268
|
+
```
|
269
|
+
|
270
|
+
Therefore, making sure you already have another mechanism to avoid race conditions, you can opt out of Advisory Lock by setting `advisory_lock` to `false` when declaring positioning:
|
271
|
+
|
272
|
+
```ruby
|
273
|
+
belongs_to :list
|
274
|
+
positioned on: :list, advisory_lock: false
|
275
|
+
```
|
276
|
+
|
246
277
|
## Development
|
247
278
|
|
248
279
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/lib/positioning/version.rb
CHANGED
data/lib/positioning.rb
CHANGED
@@ -18,7 +18,7 @@ module Positioning
|
|
18
18
|
@positioning_columns ||= {}
|
19
19
|
end
|
20
20
|
|
21
|
-
def positioned(on: [], column: :position)
|
21
|
+
def positioned(on: [], column: :position, advisory_lock: true)
|
22
22
|
unless base_class?
|
23
23
|
raise Error.new "can't be called on an abstract class or STI subclass."
|
24
24
|
end
|
@@ -43,18 +43,22 @@ module Positioning
|
|
43
43
|
super(position)
|
44
44
|
end
|
45
45
|
|
46
|
-
advisory_lock
|
46
|
+
if advisory_lock
|
47
|
+
advisory_lock_callback = AdvisoryLock.new(base_class, column)
|
47
48
|
|
48
|
-
|
49
|
-
|
50
|
-
|
49
|
+
before_create advisory_lock_callback
|
50
|
+
before_update advisory_lock_callback
|
51
|
+
before_destroy advisory_lock_callback
|
52
|
+
end
|
51
53
|
|
52
54
|
before_create { Mechanisms.new(self, column).create_position }
|
53
55
|
before_update { Mechanisms.new(self, column).update_position }
|
54
56
|
before_destroy { Mechanisms.new(self, column).destroy_position }
|
55
57
|
|
56
|
-
|
57
|
-
|
58
|
+
if advisory_lock
|
59
|
+
after_commit advisory_lock_callback
|
60
|
+
after_rollback advisory_lock_callback
|
61
|
+
end
|
58
62
|
end
|
59
63
|
end
|
60
64
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: positioning
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brendon Muir
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-05
|
11
|
+
date: 2024-07-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|