acts_as_dag 1.0.4 → 1.0.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.
- data/lib/acts_as_dag.rb +7 -2
- metadata +2 -2
data/lib/acts_as_dag.rb
CHANGED
@@ -114,6 +114,11 @@ module ActsAsDAG
|
|
114
114
|
end
|
115
115
|
|
116
116
|
module InstanceMethods
|
117
|
+
# Returns true if this record is a root node
|
118
|
+
def root?
|
119
|
+
self.class.roots.exists? self
|
120
|
+
end
|
121
|
+
|
117
122
|
# Searches all descendants for the best parent for the other
|
118
123
|
# i.e. it lets you drop the category in at the top and it drops down the list until it finds its final resting place
|
119
124
|
def plinko(other)
|
@@ -302,11 +307,11 @@ module ActsAsDAG
|
|
302
307
|
# E
|
303
308
|
#
|
304
309
|
# Now destroy all affected descendant_links (ancestors of parent (C), descendants of child (D))
|
305
|
-
descendant_type.delete_all(:ancestor_id => parent.
|
310
|
+
descendant_type.delete_all(:ancestor_id => parent.ancestor_ids, :descendant_id => child.descendant_ids)
|
306
311
|
|
307
312
|
# Now iterate through all ancestors of the descendant_links that were deleted and pick only those that have no parents, namely (A, D)
|
308
313
|
# These will be the starting points for the recreation of descendant links
|
309
|
-
starting_points = self.class.find(parent.
|
314
|
+
starting_points = self.class.find(parent.ancestor_ids + child.descendant_ids).select{|node| node.parents.empty? || node.parents == [nil] }
|
310
315
|
logger.info {"starting points are #{starting_points.collect(&:name).to_sentence}" }
|
311
316
|
|
312
317
|
# POSSIBLE OPTIMIZATION: The two starting points may share descendants. We only need to process each node once, so if we could skip dups, that would be good
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: acts_as_dag
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -43,7 +43,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
43
43
|
version: '0'
|
44
44
|
requirements: []
|
45
45
|
rubyforge_project:
|
46
|
-
rubygems_version: 1.8.
|
46
|
+
rubygems_version: 1.8.10
|
47
47
|
signing_key:
|
48
48
|
specification_version: 3
|
49
49
|
summary: Adds directed acyclic graph functionality to ActiveRecord.
|