dag 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. data/Gemfile.lock +1 -1
  2. data/README.md +2 -0
  3. data/lib/dag.rb +12 -2
  4. data/spec/lib/dag_spec.rb +21 -3
  5. metadata +1 -1
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- dag (0.0.1)
4
+ dag (0.0.2)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
data/README.md CHANGED
@@ -3,6 +3,8 @@
3
3
  Very simple directed acyclic graphs for Ruby.
4
4
 
5
5
  [![Build Status](https://travis-ci.org/kevinrutherford/dag.png)](https://travis-ci.org/kevinrutherford/dag)
6
+ [![Dependency
7
+ Status](https://gemnasium.com/kevinrutherford/dag.png)](https://gemnasium.com/kevinrutherford/dag)
6
8
  [![Code
7
9
  Climate](https://codeclimate.com/github/kevinrutherford/dag.png)](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
- def initialize
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| @vertices << 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
- it 'starts with no vertices' do
7
- subject.vertices.should be_empty
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
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dag
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: