codependency 2.3.0 → 2.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -0
- data/lib/codependency/graph.rb +22 -12
- data/lib/codependency/version.rb +1 -1
- data/spec/codependency/graph_spec.rb +24 -3
- data/spec/codependency/graph_spec/codependency_graph/scan/assets/js.txt +5 -0
- data/spec/codependency/graph_spec/codependency_graph/scan/assets/templates_js.txt +4 -0
- data/spec/codependency/graph_spec/codependency_graph/scan/breakfast/js.txt +5 -0
- data/spec/codependency/graph_spec/codependency_graph/scan/solar_system/rb.txt +5 -0
- data/spec/support/approvals.rb +4 -1
- metadata +10 -2
data/Rakefile
CHANGED
data/lib/codependency/graph.rb
CHANGED
@@ -10,15 +10,29 @@ module Codependency
|
|
10
10
|
# Any dependent files will also be recursively added to this
|
11
11
|
# graph.
|
12
12
|
def require( string )
|
13
|
-
file = path_to
|
13
|
+
file = path_to string
|
14
|
+
|
15
|
+
return if key?( file )
|
14
16
|
|
15
17
|
self[ file ] ||= parser.parse( file ).map do |short|
|
16
|
-
path_to
|
18
|
+
path_to path[ short ]
|
19
|
+
end
|
20
|
+
self[ file ].each do |dependency|
|
21
|
+
self.require dependency
|
17
22
|
end
|
18
|
-
self[ file ].each { |f| self.require( f ) unless key?( f ) }
|
19
23
|
end
|
20
24
|
alias :<< :require
|
21
25
|
|
26
|
+
##
|
27
|
+
# Parses all of the files in the given glob and adds their
|
28
|
+
# dependencies to the graph. A file in this glob is not added
|
29
|
+
# to the graph unless another file in the glob depends on it.
|
30
|
+
def scan( glob )
|
31
|
+
Dir[ glob ].map { |file| parser.parse( file ) }.flatten.uniq.each do |short|
|
32
|
+
self.require path[ short ]
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
22
36
|
##
|
23
37
|
# Returns the sorted list of files as determined by this graph,
|
24
38
|
# relative to the calling file.
|
@@ -60,18 +74,14 @@ module Codependency
|
|
60
74
|
end
|
61
75
|
|
62
76
|
##
|
63
|
-
#
|
64
|
-
# a string, returns a Pathname object populated with the relative path.
|
77
|
+
# Returns the given path, relative to the `#root` path.
|
65
78
|
def path_to( string )
|
66
79
|
path = Pathname( string )
|
67
|
-
|
68
|
-
|
80
|
+
.expand_path
|
81
|
+
.relative_path_from( root )
|
82
|
+
.to_path
|
69
83
|
|
70
|
-
|
71
|
-
path
|
72
|
-
else
|
73
|
-
Pathname( File.join( '.', path.to_path ) )
|
74
|
-
end
|
84
|
+
path.start_with?( '.' ) ? path : File.join( '.', path )
|
75
85
|
end
|
76
86
|
end
|
77
87
|
end
|
data/lib/codependency/version.rb
CHANGED
@@ -9,6 +9,8 @@ describe Codependency::Graph do
|
|
9
9
|
end
|
10
10
|
|
11
11
|
describe '#require', :fixtures => true do
|
12
|
+
before { subject.require file }
|
13
|
+
|
12
14
|
describe 'solar_system' do
|
13
15
|
example( 'body.rb' ){ verify { subject } }
|
14
16
|
example( 'earth.rb' ){ verify { subject } }
|
@@ -36,6 +38,8 @@ describe Codependency::Graph do
|
|
36
38
|
end
|
37
39
|
|
38
40
|
describe '#tsort', :fixtures => true do
|
41
|
+
before { subject.require file }
|
42
|
+
|
39
43
|
describe 'solar_system' do
|
40
44
|
example( 'body.rb' ){ verify { subject.tsort } }
|
41
45
|
example( 'earth.rb' ){ verify { subject.tsort } }
|
@@ -63,6 +67,8 @@ describe Codependency::Graph do
|
|
63
67
|
end
|
64
68
|
|
65
69
|
describe '#files', :fixtures => true do
|
70
|
+
before { subject.require file }
|
71
|
+
|
66
72
|
describe 'solar_system' do
|
67
73
|
example( 'body.rb' ){ verify { subject.files } }
|
68
74
|
example( 'earth.rb' ){ verify { subject.files } }
|
@@ -77,9 +83,9 @@ describe Codependency::Graph do
|
|
77
83
|
example( 'toast.js' ){ verify { subject.files } }
|
78
84
|
end
|
79
85
|
describe 'lox' do
|
80
|
-
example( 'money.rb' ){ expect { subject.
|
81
|
-
example( 'power.rb' ){ expect { subject.
|
82
|
-
example( 'respect.rb' ){ expect { subject.
|
86
|
+
example( 'money.rb' ){ expect { subject.files }.to raise_error( TSort::Cyclic ) }
|
87
|
+
example( 'power.rb' ){ expect { subject.files }.to raise_error( TSort::Cyclic ) }
|
88
|
+
example( 'respect.rb' ){ expect { subject.files }.to raise_error( TSort::Cyclic ) }
|
83
89
|
end
|
84
90
|
describe 'assets' do
|
85
91
|
example( 'templates/account.js' ){ verify { subject.files } }
|
@@ -88,4 +94,19 @@ describe Codependency::Graph do
|
|
88
94
|
example( 'application.js' ){ verify { subject.files } }
|
89
95
|
end
|
90
96
|
end
|
97
|
+
|
98
|
+
describe '#scan', :fixtures => true do
|
99
|
+
before { subject.scan file }
|
100
|
+
|
101
|
+
describe 'solar_system' do
|
102
|
+
example( '*.rb' ){ verify { subject.files } }
|
103
|
+
end
|
104
|
+
describe 'breakfast' do
|
105
|
+
example( '*.js' ){ verify { subject.files } }
|
106
|
+
end
|
107
|
+
describe 'assets' do
|
108
|
+
example( '*.js' ){ verify { subject.files } }
|
109
|
+
example( 'templates/*.js' ){ verify { subject.files } }
|
110
|
+
end
|
111
|
+
end
|
91
112
|
end
|
data/spec/support/approvals.rb
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
require 'rspec/approvals'
|
2
2
|
|
3
|
+
module Approvals
|
4
|
+
|
5
|
+
end
|
6
|
+
|
3
7
|
##
|
4
8
|
# Simple shared context for allowing fixture-based examples to be
|
5
9
|
# declared by using the example and example group names.
|
@@ -10,5 +14,4 @@ shared_context 'fixtures', :fixtures => true do
|
|
10
14
|
let( :file ){ File.join './spec/fixtures', dirname, basename }
|
11
15
|
|
12
16
|
before { subject.path << './spec/fixtures' }
|
13
|
-
before { subject.require file }
|
14
17
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: codependency
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.3.
|
4
|
+
version: 2.3.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-05-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -125,6 +125,10 @@ files:
|
|
125
125
|
- spec/codependency/graph_spec/codependency_graph/require/solar_system/mars_rb.txt
|
126
126
|
- spec/codependency/graph_spec/codependency_graph/require/solar_system/phobos_rb.txt
|
127
127
|
- spec/codependency/graph_spec/codependency_graph/require/solar_system/planet_rb.txt
|
128
|
+
- spec/codependency/graph_spec/codependency_graph/scan/assets/js.txt
|
129
|
+
- spec/codependency/graph_spec/codependency_graph/scan/assets/templates_js.txt
|
130
|
+
- spec/codependency/graph_spec/codependency_graph/scan/breakfast/js.txt
|
131
|
+
- spec/codependency/graph_spec/codependency_graph/scan/solar_system/rb.txt
|
128
132
|
- spec/codependency/graph_spec/codependency_graph/tsort/assets/application_js.txt
|
129
133
|
- spec/codependency/graph_spec/codependency_graph/tsort/assets/templates_account_js.txt
|
130
134
|
- spec/codependency/graph_spec/codependency_graph/tsort/assets/templates_history_js.txt
|
@@ -214,6 +218,10 @@ test_files:
|
|
214
218
|
- spec/codependency/graph_spec/codependency_graph/require/solar_system/mars_rb.txt
|
215
219
|
- spec/codependency/graph_spec/codependency_graph/require/solar_system/phobos_rb.txt
|
216
220
|
- spec/codependency/graph_spec/codependency_graph/require/solar_system/planet_rb.txt
|
221
|
+
- spec/codependency/graph_spec/codependency_graph/scan/assets/js.txt
|
222
|
+
- spec/codependency/graph_spec/codependency_graph/scan/assets/templates_js.txt
|
223
|
+
- spec/codependency/graph_spec/codependency_graph/scan/breakfast/js.txt
|
224
|
+
- spec/codependency/graph_spec/codependency_graph/scan/solar_system/rb.txt
|
217
225
|
- spec/codependency/graph_spec/codependency_graph/tsort/assets/application_js.txt
|
218
226
|
- spec/codependency/graph_spec/codependency_graph/tsort/assets/templates_account_js.txt
|
219
227
|
- spec/codependency/graph_spec/codependency_graph/tsort/assets/templates_history_js.txt
|