dag 0.0.2 → 0.0.3
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/Gemfile.lock +1 -1
- data/README.md +2 -0
- data/lib/dag.rb +12 -2
- data/spec/lib/dag_spec.rb +21 -3
- metadata +1 -1
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -3,6 +3,8 @@
|
|
3
3
|
Very simple directed acyclic graphs for Ruby.
|
4
4
|
|
5
5
|
[](https://travis-ci.org/kevinrutherford/dag)
|
6
|
+
[](https://gemnasium.com/kevinrutherford/dag)
|
6
8
|
[](https://codeclimate.com/github/kevinrutherford/dag)
|
8
10
|
|
data/lib/dag.rb
CHANGED
@@ -6,13 +6,23 @@ class DAG
|
|
6
6
|
|
7
7
|
attr_reader :vertices, :edges
|
8
8
|
|
9
|
-
|
9
|
+
#
|
10
|
+
# Create a new Directed Acyclic Graph
|
11
|
+
#
|
12
|
+
# @param [Hash] options configuration options
|
13
|
+
# @option options [Module] mix this module into any created +Vertex+
|
14
|
+
#
|
15
|
+
def initialize(options = {})
|
10
16
|
@vertices = []
|
11
17
|
@edges = []
|
18
|
+
@mixin = options[:mixin]
|
12
19
|
end
|
13
20
|
|
14
21
|
def add_vertex(payload = {})
|
15
|
-
Vertex.new(self, payload).tap {|v|
|
22
|
+
Vertex.new(self, payload).tap {|v|
|
23
|
+
v.extend(@mixin) if @mixin
|
24
|
+
@vertices << v
|
25
|
+
}
|
16
26
|
end
|
17
27
|
|
18
28
|
def add_edge(attrs)
|
data/spec/lib/dag_spec.rb
CHANGED
@@ -3,9 +3,8 @@ require 'spec_helper'
|
|
3
3
|
describe DAG do
|
4
4
|
|
5
5
|
context 'when new' do
|
6
|
-
|
7
|
-
|
8
|
-
end
|
6
|
+
its(:vertices) { should be_empty }
|
7
|
+
its(:edges) { should be_empty }
|
9
8
|
end
|
10
9
|
|
11
10
|
context 'with one vertex' do
|
@@ -21,6 +20,25 @@ describe DAG do
|
|
21
20
|
end
|
22
21
|
end
|
23
22
|
|
23
|
+
context 'using a mix-in module' do
|
24
|
+
subject { DAG.new(mixin: Thing) }
|
25
|
+
let(:v) { subject.add_vertex(name: 'Fred') }
|
26
|
+
|
27
|
+
module Thing
|
28
|
+
def my_name
|
29
|
+
payload[:name]
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'mixes the module into evey vertex' do
|
34
|
+
(Thing === v).should be_true
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'allows the module to access the payload' do
|
38
|
+
v.my_name.should == 'Fred'
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
24
42
|
context 'creating an edge' do
|
25
43
|
let(:v1) { subject.add_vertex }
|
26
44
|
|