acts-as-dag 2.5.3 → 2.5.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +2 -2
- data/VERSION +1 -1
- data/lib/dag/edges.rb +23 -1
- data/test/dag_test.rb +30 -1
- data/test/database.test +0 -0
- metadata +5 -5
data/README.rdoc
CHANGED
@@ -6,11 +6,11 @@ Acts As Dag, short for Acts As Directed Acyclic Graph, is a plugin which allows
|
|
6
6
|
|
7
7
|
Say you have been using one of the many great plugins that allow for Tree hierarchy like: acts_as_tree or acts_as_nested_set, acts_as_better_nested_set, etc. Yet, you feel something is missing. Tree's are just not good enough. You want to allow each record to have multiple parent objects within a hierarchy as well as multiple children. Then you are going to need a DAG instead of a tree, and thats were this plugin becomes useful.
|
8
8
|
|
9
|
-
Version 1.1.
|
9
|
+
Version 1.1.2 tested using Rails 2.3.8 and Ruby 1.9.2-p0 and Ruby 1.8.x.
|
10
10
|
|
11
11
|
Version 2.0.x tested using Rails 3.0.0 and Ruby 1.9.2-p0, without major structural changes to code from the Rails 3 framework. Removes all deprecation warnings I have received while using AAD and Rails 3.0.0.
|
12
12
|
|
13
|
-
Version 2.5.
|
13
|
+
Version 2.5.3 is based on Rails 3.0.0 and uses all of the new ActiveModel/ActiveRecord goodness found there.
|
14
14
|
|
15
15
|
=== What's a DAG?
|
16
16
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.5.
|
1
|
+
2.5.4
|
data/lib/dag/edges.rb
CHANGED
@@ -82,7 +82,7 @@ module Dag
|
|
82
82
|
def longest_path_between(ancestor, descendant, path=[])
|
83
83
|
longest = []
|
84
84
|
ancestor.children.each do |child|
|
85
|
-
if child ==
|
85
|
+
if child == descendant
|
86
86
|
temp = path.clone
|
87
87
|
temp << child
|
88
88
|
if temp.length > longest.length
|
@@ -100,6 +100,28 @@ module Dag
|
|
100
100
|
longest
|
101
101
|
end
|
102
102
|
|
103
|
+
#Finds the shortest path between ancestor and descendant returning as an array
|
104
|
+
def shortest_path_between(ancestor, descendant, path=[])
|
105
|
+
shortest = []
|
106
|
+
ancestor.children.each do |child|
|
107
|
+
if child == descendant
|
108
|
+
temp = path.clone
|
109
|
+
temp << child
|
110
|
+
if shortest.blank? || temp.length < shortest.length
|
111
|
+
shortest = temp
|
112
|
+
end
|
113
|
+
elsif self.connected?(child, descendant)
|
114
|
+
temp = path.clone
|
115
|
+
temp << child
|
116
|
+
temp = self.shortest_path_between(child, descendant, temp)
|
117
|
+
if shortest.blank? || temp.length < shortest.length
|
118
|
+
shortest = temp
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
return shortest
|
123
|
+
end
|
124
|
+
|
103
125
|
#Determines if an edge exists between two points
|
104
126
|
def edge?(ancestor, descendant)
|
105
127
|
!self.find_edge(ancestor, descendant).nil?
|
data/test/dag_test.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'test/unit'
|
2
2
|
require 'rubygems'
|
3
|
-
gem 'activerecord', '= 3.0.
|
3
|
+
gem 'activerecord', '= 3.0.3'
|
4
4
|
require "./init"
|
5
5
|
|
6
6
|
|
@@ -813,4 +813,33 @@ class DagTest < Test::Unit::TestCase
|
|
813
813
|
b.reload
|
814
814
|
assert !b.root_for_beta_nodes?
|
815
815
|
end
|
816
|
+
|
817
|
+
#Tests that longest_path_between works
|
818
|
+
def test_longest_path_between
|
819
|
+
a = Node.create!
|
820
|
+
b = Node.create!
|
821
|
+
c = Node.create!
|
822
|
+
d = Node.create!
|
823
|
+
e = Default.create_edge(a,b)
|
824
|
+
e = Default.create_edge(b,c)
|
825
|
+
e = Default.create_edge(a,c)
|
826
|
+
e = Default.create_edge(c,d)
|
827
|
+
path = Default.longest_path_between(a,d)
|
828
|
+
assert_equal [b,c,d], path
|
829
|
+
end
|
830
|
+
|
831
|
+
#Tests that shortest_path_between works
|
832
|
+
def test_shortest_path_between
|
833
|
+
a = Node.create!
|
834
|
+
b = Node.create!
|
835
|
+
c = Node.create!
|
836
|
+
d = Node.create!
|
837
|
+
e = Default.create_edge(a,b)
|
838
|
+
e = Default.create_edge(b,c)
|
839
|
+
e = Default.create_edge(a,c)
|
840
|
+
e = Default.create_edge(c,d)
|
841
|
+
path = Default.shortest_path_between(a,d)
|
842
|
+
assert_equal [c,d], path
|
843
|
+
end
|
844
|
+
|
816
845
|
end
|
data/test/database.test
CHANGED
Binary file
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 2
|
7
7
|
- 5
|
8
|
-
-
|
9
|
-
version: 2.5.
|
8
|
+
- 4
|
9
|
+
version: 2.5.4
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Matthew Leventi
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date:
|
18
|
+
date: 2011-02-04 00:00:00 -08:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|
@@ -47,8 +47,8 @@ homepage: http://github.com/resgraph/acts-as-dag
|
|
47
47
|
licenses: []
|
48
48
|
|
49
49
|
post_install_message:
|
50
|
-
rdoc_options:
|
51
|
-
|
50
|
+
rdoc_options: []
|
51
|
+
|
52
52
|
require_paths:
|
53
53
|
- lib
|
54
54
|
required_ruby_version: !ruby/object:Gem::Requirement
|