dsort 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/dsort/version.rb +1 -1
- data/lib/dsort.rb +5 -11
- data/spec/dsort_spec.rb +14 -5
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c9ed6fb53266348e036bed7d5f6ca9c31763d9db4f41803eebe86c9b0ad0811f
|
4
|
+
data.tar.gz: 517b02275b892c789cb9aa217d15d1ed5c0a7ec5d9f0d4310e0dbfd4a732d734
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 85946f69bb5bd4d9166e3a2dbb1e785ddedf70189d4b7aa3a1ce80a84d697dd4c28f4af70559b855ccbdc7003a474481a4800dfc6f19e854fa026b60dbb2fc64
|
7
|
+
data.tar.gz: f477f1eafdd649013677a672d9f13db5aa1bbdf558135caff60edd6b39c2c5bcf877ddb3b613fc0a941a39778f27cd9d408e570b50034f480d66f14dd1e04029
|
data/lib/dsort/version.rb
CHANGED
data/lib/dsort.rb
CHANGED
@@ -110,6 +110,7 @@ module DSort
|
|
110
110
|
@deps = {}
|
111
111
|
if block_given?
|
112
112
|
a = [a] if !a.is_a?(Array)
|
113
|
+
@pool = {}
|
113
114
|
a.each { |elem| find_dependencies(elem, &block) }
|
114
115
|
else
|
115
116
|
a.each { |obj, deps|
|
@@ -134,20 +135,13 @@ module DSort
|
|
134
135
|
private
|
135
136
|
def find_dependencies(a, &block)
|
136
137
|
block.call(a).each { |d|
|
137
|
-
(@deps[a] ||= [])
|
138
|
-
|
138
|
+
if !(@deps[a] ||= []).include? d # Cyclic dependency
|
139
|
+
@deps[a] << d
|
140
|
+
find_dependencies(d, &block)
|
141
|
+
end
|
139
142
|
}
|
140
143
|
end
|
141
144
|
end
|
142
145
|
end
|
143
146
|
end
|
144
147
|
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
data/spec/dsort_spec.rb
CHANGED
@@ -89,11 +89,20 @@ describe DSort do
|
|
89
89
|
end
|
90
90
|
end
|
91
91
|
context "with circular dependencies" do
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
92
|
+
context "should raise DSort::Cyclic" do
|
93
|
+
it "when given an array argument" do
|
94
|
+
lambda {
|
95
|
+
pairs = [[:a, :b], [:b, :a]]
|
96
|
+
DSort.dsort(pairs).should == 1
|
97
|
+
}.should raise_error(DSort::Cyclic)
|
98
|
+
end
|
99
|
+
|
100
|
+
it "when given a block argument" do
|
101
|
+
l = lambda { |node| [node == :a ? :b : :a] }
|
102
|
+
expect {
|
103
|
+
DSort.dsort(:a, &l)
|
104
|
+
}.to raise_error(DSort::Cyclic)
|
105
|
+
end
|
97
106
|
end
|
98
107
|
end
|
99
108
|
end
|