monarchy 1.1.4 → 1.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f963493605d696311041686e1851bb817c7ffc79
4
- data.tar.gz: 911449908792e86543e9e2f5f27419c83259f9dc
3
+ metadata.gz: ae3074e01b50dd43b63d376ebb3f2410a9e6f588
4
+ data.tar.gz: c37f5e0d3bb7dd2998bbab3b0624c989e3027b38
5
5
  SHA512:
6
- metadata.gz: b4f3cf8d4938a0b8bb4aafcf4b66839ea0c84fd5c2326d391804a5ce2dc0f2d768dba937202b594d07870cbfabd13d0e6e67dde2774963d0d766da547b069dab
7
- data.tar.gz: 69f1a19456a597ea7e418ed13721ef42c6864074ba3e24b3d40f63a951ec21af4aec4a4376007c8f83260e6e2e3b2403106458765460bbdfeb1513e18646222a
6
+ metadata.gz: ba65132a3f0e45e64ceec663be0a0c030013aea2d3c66e8bf5495b908a9e79f8bf04509b0a5a4163728db1828007e707be5cfc1e69de3e946df1ee270bad6cf8
7
+ data.tar.gz: 9139f0b7de797402b124f2eb31fdb213bd72c317ebe30ef90bedbb4c755297424f7f30bcadf56b243279200b1b09d9958f44c78b9ef2b33c7f983d5c564471a5
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- monarchy (1.1.4)
4
+ monarchy (1.1.5)
5
5
  active_record_union (= 1.2.0)
6
6
  closure_tree (= 6.1.0)
7
7
  configurations (= 2.2.0)
@@ -10,8 +10,8 @@ module Monarchy
10
10
 
11
11
  parent_as(options[:parent_as]) if options[:parent_as]
12
12
 
13
- after_create :ensure_hierarchy
14
- after_save :assign_parent
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(:hierarchy))
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
- private
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
- parent = self.class.parentize
85
+ parentize = self.class.parentize
85
86
 
86
- if parent
87
- was_changed = changes["#{parent}_id"] || changes["#{parent}_type"]
88
- self.parent = send(parent) if was_changed || force
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
 
@@ -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!'
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Monarchy
3
- VERSION = '1.1.4'
3
+ VERSION = '1.1.5'
4
4
  end
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
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-16 00:00:00.000000000 Z
11
+ date: 2016-08-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails