para 0.7.2 → 0.7.3.p1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/models/para/page/section.rb +1 -1
- data/app/models/para/page/section_resource.rb +1 -1
- data/lib/para/orderable.rb +33 -4
- data/lib/para/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9914054a92494ea3515aff6b5d6666cedac890dd
|
4
|
+
data.tar.gz: e315815203d4e228705bcf9d0c65f79ce90628e2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bacae843ada593e3530f3e71a9aa432a1db3a45b17d1e4bacd7acc99033ba4eddbed1aa514abce6e96240bc7b0b52d7a5f67b64ff630717d8c9534c00b517f1c
|
7
|
+
data.tar.gz: a332a031f1e49cb77eda71bdffd8166055e5b8962432513ed444f2d096f61c8b29a693fd209c08c467e6748192f2ce4b1dc00d1a9a1993c529504592b2ba83de
|
data/lib/para/orderable.rb
CHANGED
@@ -4,14 +4,18 @@ module Para
|
|
4
4
|
|
5
5
|
included do
|
6
6
|
scope :ordered, -> { order("#{ table_name }.position ASC") }
|
7
|
+
|
7
8
|
before_create :orderable_assign_position
|
9
|
+
after_commit :reprocess_ordering
|
10
|
+
after_destroy :reprocess_ordering
|
8
11
|
end
|
9
12
|
|
13
|
+
private
|
14
|
+
|
10
15
|
def orderable_assign_position
|
11
16
|
return if attribute_present?(:position)
|
12
17
|
|
13
|
-
last_resource =
|
14
|
-
.ordered
|
18
|
+
last_resource = orderable_scope
|
15
19
|
.where.not(position: nil)
|
16
20
|
.select(:position)
|
17
21
|
.first
|
@@ -22,20 +26,45 @@ module Para
|
|
22
26
|
0
|
23
27
|
end
|
24
28
|
end
|
29
|
+
|
30
|
+
# Unfragment existing resources positions
|
31
|
+
#
|
32
|
+
def reprocess_ordering
|
33
|
+
orderable_scope.each_with_index do |resource, index|
|
34
|
+
resource.update_column(:position, index)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def orderable_scope
|
39
|
+
if (parent = _orderable_options[:parent]) && (as = _orderable_options[:as])
|
40
|
+
try(parent).try(as).try(:ordered) || []
|
41
|
+
else
|
42
|
+
self.class.unscoped.ordered
|
43
|
+
end
|
44
|
+
end
|
25
45
|
end
|
26
46
|
|
27
47
|
module ActiveRecordOrderableMixin
|
28
48
|
extend ActiveSupport::Concern
|
29
49
|
|
30
50
|
included do
|
31
|
-
class_attribute :orderable
|
51
|
+
class_attribute :orderable, :_orderable_options
|
32
52
|
end
|
33
53
|
|
34
54
|
module ClassMethods
|
35
|
-
def acts_as_orderable
|
55
|
+
def acts_as_orderable(options = {})
|
36
56
|
return if orderable?
|
37
57
|
|
58
|
+
unless (
|
59
|
+
( options[:parent] && options[:as]) ||
|
60
|
+
(!options[:parent] && !options[:as])
|
61
|
+
)
|
62
|
+
raise "You need to either pass :parent and :as options to the " \
|
63
|
+
"acts_as_orderable macro, or no options at all."
|
64
|
+
end
|
65
|
+
|
38
66
|
self.orderable = true
|
67
|
+
self._orderable_options = options
|
39
68
|
include Para::Orderable
|
40
69
|
end
|
41
70
|
|
data/lib/para/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: para
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.3.p1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Valentin Ballestrino
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-12-
|
11
|
+
date: 2018-12-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -833,9 +833,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
833
833
|
version: '0'
|
834
834
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
835
835
|
requirements:
|
836
|
-
- - "
|
836
|
+
- - ">"
|
837
837
|
- !ruby/object:Gem::Version
|
838
|
-
version:
|
838
|
+
version: 1.3.1
|
839
839
|
requirements: []
|
840
840
|
rubyforge_project:
|
841
841
|
rubygems_version: 2.6.11
|