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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e29b9d36c3e4bb2c6122b967ffdfa3e3609a01fe5dfe37cf6c1d4d319a8495b3
4
- data.tar.gz: 81fffd543f6dd5518583cca18dd1ba73d69ab164fa88895943bb80e1553eee32
3
+ metadata.gz: c9ed6fb53266348e036bed7d5f6ca9c31763d9db4f41803eebe86c9b0ad0811f
4
+ data.tar.gz: 517b02275b892c789cb9aa217d15d1ed5c0a7ec5d9f0d4310e0dbfd4a732d734
5
5
  SHA512:
6
- metadata.gz: 9a74383d8fc09440f1a53ecf03dccc6900c16a0db9633292d80ab06a8751452accbb4f4ad91ce4b41474d58e52a5f77b79acf555c7c354dfb984664da182610a
7
- data.tar.gz: af569f855ea9d98b72909e6b4b9d607d8072bcd33b040e8a5eb434e26c4d3be75c9470d41fc6f1ac7d60e4ea4470ef8080358b5a95b2bb11518966abfb50ece5
6
+ metadata.gz: 85946f69bb5bd4d9166e3a2dbb1e785ddedf70189d4b7aa3a1ce80a84d697dd4c28f4af70559b855ccbdc7003a474481a4800dfc6f19e854fa026b60dbb2fc64
7
+ data.tar.gz: f477f1eafdd649013677a672d9f13db5aa1bbdf558135caff60edd6b39c2c5bcf877ddb3b613fc0a941a39778f27cd9d408e570b50034f480d66f14dd1e04029
data/lib/dsort/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Dsort
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
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] ||= []) << d
138
- find_dependencies(d, &block)
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
- it "should raise DSort::Cyclic" do
93
- lambda {
94
- pairs = [[:a, :b], [:b, :a]]
95
- DSort.dsort(pairs).should == 1
96
- }.should raise_error(DSort::Cyclic)
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dsort
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Claus Rasmussen