dependable 0.0.3 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,12 +1,21 @@
1
1
  module Dependable
2
-
3
- def dependencies=(dependencies)
4
- raise ArgumentError.new('Dependencies must be enumerable') unless dependencies.kind_of?(Enumerable) # TODO debatable whether this should be here
5
- @dependencies = dependencies
2
+
3
+ attr_reader :dependencies
4
+
5
+ def clear_dependencies
6
+ @dependencies = []
6
7
  end
7
8
 
8
- def dependencies
9
- @dependencies || []
9
+ def needs(*things)
10
+ raise DependencyError.new("Circular Dependency Detected") if things.any? { |thing| thing.dependent_on?(self) }
11
+ @dependencies ||= []
12
+ @dependencies.concat things
13
+ end
14
+
15
+ # Bad recursive performance - should use trees
16
+ def dependent_on?(thing)
17
+ return true if self == thing
18
+ @dependencies && @dependencies.any? { |d| d.dependent_on?(thing) }
10
19
  end
11
20
 
12
21
  def load_path(include_self = true)
@@ -27,5 +36,8 @@ module Dependable
27
36
  puts
28
37
  end
29
38
  end
39
+
40
+ class DependencyError < ArgumentError
41
+ end
30
42
 
31
43
  end
@@ -1,5 +1,5 @@
1
1
  module Dependable
2
2
 
3
- VERSION = '0.0.3'
3
+ VERSION = '0.1.0'
4
4
 
5
5
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dependable
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 27
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
+ - 1
8
9
  - 0
9
- - 3
10
- version: 0.0.3
10
+ version: 0.1.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - John Crepezzi
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-07-30 00:00:00 -04:00
18
+ date: 2010-08-25 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency