monarchy 1.1.4 → 1.1.5
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/Gemfile.lock +1 -1
- data/lib/monarchy/acts_as_resource.rb +13 -12
- data/lib/monarchy/tasks.rb +1 -1
- data/lib/monarchy/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ae3074e01b50dd43b63d376ebb3f2410a9e6f588
|
4
|
+
data.tar.gz: c37f5e0d3bb7dd2998bbab3b0624c989e3027b38
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ba65132a3f0e45e64ceec663be0a0c030013aea2d3c66e8bf5495b908a9e79f8bf04509b0a5a4163728db1828007e707be5cfc1e69de3e946df1ee270bad6cf8
|
7
|
+
data.tar.gz: 9139f0b7de797402b124f2eb31fdb213bd72c317ebe30ef90bedbb4c755297424f7f30bcadf56b243279200b1b09d9958f44c78b9ef2b33c7f983d5c564471a5
|
data/Gemfile.lock
CHANGED
@@ -10,8 +10,8 @@ module Monarchy
|
|
10
10
|
|
11
11
|
parent_as(options[:parent_as]) if options[:parent_as]
|
12
12
|
|
13
|
-
|
14
|
-
|
13
|
+
after_update :assign_parent
|
14
|
+
after_create :ensure_hierarchy, :assign_parent
|
15
15
|
|
16
16
|
has_many :members, through: :hierarchy, class_name: "::#{Monarchy.member_class}"
|
17
17
|
has_many :users, through: :members, class_name: "::#{Monarchy.user_class}"
|
@@ -24,13 +24,14 @@ module Monarchy
|
|
24
24
|
end
|
25
25
|
|
26
26
|
module SupportMethods
|
27
|
-
attr_accessor :parentize, :acting_as_resource
|
27
|
+
attr_accessor :parentize, :acting_as_resource, :automatic_hierarchy
|
28
28
|
|
29
29
|
private
|
30
30
|
|
31
31
|
def setup_acting
|
32
32
|
Monarchy.resource_classes << self
|
33
33
|
@acting_as_resource = true
|
34
|
+
@automatic_hierarchy = true
|
34
35
|
end
|
35
36
|
|
36
37
|
def parent_as(name)
|
@@ -55,7 +56,7 @@ module Monarchy
|
|
55
56
|
|
56
57
|
def parent=(resource)
|
57
58
|
if hierarchy
|
58
|
-
hierarchy.update(parent: resource.try(:
|
59
|
+
hierarchy.update(parent: resource.try(:ensure_hierarchy))
|
59
60
|
else
|
60
61
|
@parent = resource
|
61
62
|
end
|
@@ -70,22 +71,22 @@ module Monarchy
|
|
70
71
|
@children = array
|
71
72
|
end
|
72
73
|
|
73
|
-
|
74
|
-
|
75
|
-
def ensure_hierarchy
|
74
|
+
def ensure_hierarchy(force = false)
|
76
75
|
self.hierarchy ||= Monarchy::Hierarchy.create(
|
77
76
|
resource: self,
|
78
77
|
parent: parent.try(:hierarchy),
|
79
78
|
children: hierarchies_for(children)
|
80
|
-
)
|
79
|
+
) if self.class.automatic_hierarchy || force
|
81
80
|
end
|
82
81
|
|
82
|
+
private
|
83
|
+
|
83
84
|
def assign_parent(force = false)
|
84
|
-
|
85
|
+
parentize = self.class.parentize
|
85
86
|
|
86
|
-
if
|
87
|
-
was_changed = changes["#{
|
88
|
-
self.parent = send(
|
87
|
+
if parentize
|
88
|
+
was_changed = changes["#{parentize}_id"] || changes["#{parentize}_type"]
|
89
|
+
self.parent = send(parentize) if was_changed || force
|
89
90
|
end
|
90
91
|
end
|
91
92
|
|
data/lib/monarchy/tasks.rb
CHANGED
@@ -16,7 +16,7 @@ module Monarchy
|
|
16
16
|
p 'Monarchy hierarchization...'
|
17
17
|
Monarchy.resource_classes.with_progress.each do |klass|
|
18
18
|
klass.all.each do |model|
|
19
|
-
model.send(:ensure_hierarchy)
|
19
|
+
model.send(:ensure_hierarchy, true)
|
20
20
|
end
|
21
21
|
end
|
22
22
|
p 'Monarchy hierarchization ended!'
|
data/lib/monarchy/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: monarchy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Exelord
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-08-
|
11
|
+
date: 2016-08-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|