nanoc 4.8.0 → 4.8.1
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.
- checksums.yaml +4 -4
- data/NEWS.md +7 -1
- data/lib/nanoc/base/entities/directed_graph.rb +20 -44
- data/lib/nanoc/base/entities/props.rb +4 -0
- data/lib/nanoc/cli.rb +2 -2
- data/lib/nanoc/version.rb +1 -1
- data/spec/nanoc/base/directed_graph_spec.rb +18 -54
- data/spec/spec_helper.rb +1 -1
- data/test/base/test_directed_graph.rb +2 -22
- data/test/helper.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8537bc61d500ed5bae70dcae626b5991fd43dea7
|
4
|
+
data.tar.gz: 565524a4ffb2733eb6b05fe547c3ee7e2b0788e9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b174cadc89845ac6b8e7fec2cea4f9feb4022eef44653a6f505c9eb00d10c59c9ba3fc73d5b2f61cb9a928248fac433944d81e780eb0934dd309939def7ecd2a
|
7
|
+
data.tar.gz: 78c42adc2b1bc34501aaae163baffc6ab839b45f81d80430a924cca13d0d3a63573702c0a02bcdce4e788a7a5cf560c5250c09617fa065f1c0cc124086412516
|
data/NEWS.md
CHANGED
@@ -7,28 +7,30 @@ module Nanoc::Int
|
|
7
7
|
# @example Creating and using a directed graph
|
8
8
|
#
|
9
9
|
# # Create a graph with three vertices
|
10
|
-
# graph = Nanoc::Int::DirectedGraph.new(%w( a b c d e ))
|
10
|
+
# graph = Nanoc::Int::DirectedGraph.new(%w( a b c d e f g ))
|
11
11
|
#
|
12
12
|
# # Add edges
|
13
13
|
# graph.add_edge('a', 'b')
|
14
14
|
# graph.add_edge('b', 'c')
|
15
|
+
# graph.add_edge('b', 'f')
|
16
|
+
# graph.add_edge('b', 'g')
|
15
17
|
# graph.add_edge('c', 'd')
|
16
|
-
# graph.add_edge('
|
18
|
+
# graph.add_edge('d', 'e')
|
17
19
|
#
|
18
|
-
# # Get (direct)
|
19
|
-
# graph.
|
20
|
-
# # => %w(
|
21
|
-
# graph.
|
22
|
-
# # => %w( b c d
|
20
|
+
# # Get (direct) predecessors
|
21
|
+
# graph.direct_predecessors_of('b').sort
|
22
|
+
# # => %w( a )
|
23
|
+
# graph.predecessors_of('e').sort
|
24
|
+
# # => %w( a b c d )
|
23
25
|
#
|
24
26
|
# # Modify edges
|
25
27
|
# graph.delete_edges_to('c')
|
26
28
|
#
|
27
|
-
# # Get (direct)
|
28
|
-
# graph.
|
29
|
-
# # => %w(
|
30
|
-
# graph.
|
31
|
-
# # => %w(
|
29
|
+
# # Get (direct) predecessors again
|
30
|
+
# graph.direct_predecessors_of('e').sort
|
31
|
+
# # => %w( d )
|
32
|
+
# graph.predecessors_of('e').sort
|
33
|
+
# # => %w( c d )
|
32
34
|
#
|
33
35
|
# @api private
|
34
36
|
class DirectedGraph
|
@@ -42,7 +44,6 @@ module Nanoc::Int
|
|
42
44
|
@vertices[v] = @next_vertex_idx.tap { @next_vertex_idx += 1 }
|
43
45
|
end
|
44
46
|
|
45
|
-
@from_graph = {}
|
46
47
|
@to_graph = {}
|
47
48
|
|
48
49
|
@edge_props = {}
|
@@ -53,8 +54,8 @@ module Nanoc::Int
|
|
53
54
|
def inspect
|
54
55
|
s = []
|
55
56
|
|
56
|
-
@vertices.each_pair do |
|
57
|
-
|
57
|
+
@vertices.each_pair do |v2, _|
|
58
|
+
direct_predecessors_of(v2).each do |v1|
|
58
59
|
s << [v1.inspect + ' -> ' + v2.inspect + ' props=' + @edge_props[[v1, v2]].inspect]
|
59
60
|
end
|
60
61
|
end
|
@@ -75,9 +76,6 @@ module Nanoc::Int
|
|
75
76
|
add_vertex(from)
|
76
77
|
add_vertex(to)
|
77
78
|
|
78
|
-
@from_graph[from] ||= Set.new
|
79
|
-
@from_graph[from] << to
|
80
|
-
|
81
79
|
@to_graph[to] ||= Set.new
|
82
80
|
@to_graph[to] << from
|
83
81
|
|
@@ -108,7 +106,6 @@ module Nanoc::Int
|
|
108
106
|
return if @to_graph[to].nil?
|
109
107
|
|
110
108
|
@to_graph[to].each do |from|
|
111
|
-
@from_graph[from].delete(to)
|
112
109
|
@edge_props.delete([from, to])
|
113
110
|
end
|
114
111
|
@to_graph.delete(to)
|
@@ -125,17 +122,7 @@ module Nanoc::Int
|
|
125
122
|
#
|
126
123
|
# @return [Array] Direct predecessors of the given vertex
|
127
124
|
def direct_predecessors_of(to)
|
128
|
-
@to_graph
|
129
|
-
end
|
130
|
-
|
131
|
-
# Returns the direct successors of the given vertex, i.e. the vertices y
|
132
|
-
# where there is an edge from the given vertex x to y.
|
133
|
-
#
|
134
|
-
# @param from The vertex of which the successors should be calculated
|
135
|
-
#
|
136
|
-
# @return [Array] Direct successors of the given vertex
|
137
|
-
def direct_successors_of(from)
|
138
|
-
@from_graph[from].to_a
|
125
|
+
@to_graph.fetch(to, Set.new)
|
139
126
|
end
|
140
127
|
|
141
128
|
# Returns the predecessors of the given vertex, i.e. the vertices x for
|
@@ -148,16 +135,6 @@ module Nanoc::Int
|
|
148
135
|
@predecessors[to] ||= recursively_find_vertices(to, :direct_predecessors_of)
|
149
136
|
end
|
150
137
|
|
151
|
-
# Returns the successors of the given vertex, i.e. the vertices y for
|
152
|
-
# which there is a path from the given vertex x to y.
|
153
|
-
#
|
154
|
-
# @param from The vertex of which the successors should be calculated
|
155
|
-
#
|
156
|
-
# @return [Array] Successors of the given vertex
|
157
|
-
def successors_of(from)
|
158
|
-
@successors[from] ||= recursively_find_vertices(from, :direct_successors_of)
|
159
|
-
end
|
160
|
-
|
161
138
|
def props_for(from, to)
|
162
139
|
@edge_props[[from, to]]
|
163
140
|
end
|
@@ -173,8 +150,8 @@ module Nanoc::Int
|
|
173
150
|
# @return [Array] The list of all edges in this graph.
|
174
151
|
def edges
|
175
152
|
result = []
|
176
|
-
@vertices.each_pair do |
|
177
|
-
|
153
|
+
@vertices.each_pair do |v2, i2|
|
154
|
+
direct_predecessors_of(v2).map { |v1| [@vertices[v1], v1] }.each do |i1, v1|
|
178
155
|
result << [i1, i2, @edge_props[[v1, v2]]]
|
179
156
|
end
|
180
157
|
end
|
@@ -187,7 +164,6 @@ module Nanoc::Int
|
|
187
164
|
# graph representation is changed.
|
188
165
|
def invalidate_caches
|
189
166
|
@predecessors = {}
|
190
|
-
@successors = {}
|
191
167
|
end
|
192
168
|
|
193
169
|
# Recursively finds vertices, starting at the vertex start, using the
|
@@ -212,7 +188,7 @@ module Nanoc::Int
|
|
212
188
|
end
|
213
189
|
end
|
214
190
|
|
215
|
-
all_vertices
|
191
|
+
all_vertices
|
216
192
|
end
|
217
193
|
end
|
218
194
|
end
|
@@ -18,6 +18,8 @@ module Nanoc::Int
|
|
18
18
|
|
19
19
|
@attributes =
|
20
20
|
case attributes
|
21
|
+
when Set
|
22
|
+
attributes
|
21
23
|
when Enumerable
|
22
24
|
Set.new(attributes)
|
23
25
|
else
|
@@ -26,6 +28,8 @@ module Nanoc::Int
|
|
26
28
|
|
27
29
|
@raw_content =
|
28
30
|
case raw_content
|
31
|
+
when Set
|
32
|
+
raw_content
|
29
33
|
when Enumerable
|
30
34
|
Set.new(raw_content)
|
31
35
|
else
|
data/lib/nanoc/cli.rb
CHANGED
@@ -96,7 +96,7 @@ module Nanoc::CLI
|
|
96
96
|
@root_command = nil
|
97
97
|
|
98
98
|
# Add root command
|
99
|
-
filename =
|
99
|
+
filename = __dir__ + '/cli/commands/nanoc.rb'
|
100
100
|
@root_command = load_command_at(filename)
|
101
101
|
|
102
102
|
# Add help command
|
@@ -104,7 +104,7 @@ module Nanoc::CLI
|
|
104
104
|
add_command(help_cmd)
|
105
105
|
|
106
106
|
# Add other commands
|
107
|
-
cmd_filenames = Dir[
|
107
|
+
cmd_filenames = Dir[__dir__ + '/cli/commands/*.rb']
|
108
108
|
cmd_filenames.each do |cmd_filename|
|
109
109
|
next if File.basename(cmd_filename, '.rb') == 'nanoc'
|
110
110
|
cmd = load_command_at(cmd_filename)
|
data/lib/nanoc/version.rb
CHANGED
@@ -81,9 +81,18 @@ describe Nanoc::Int::DirectedGraph do
|
|
81
81
|
it { is_expected.to be_empty }
|
82
82
|
end
|
83
83
|
|
84
|
+
context 'requested for non-existant vertex' do
|
85
|
+
subject { graph.direct_predecessors_of('12345') }
|
86
|
+
|
87
|
+
it { is_expected.to be_empty }
|
88
|
+
it { is_expected.to be_a(Set) }
|
89
|
+
end
|
90
|
+
|
84
91
|
context 'one edge to' do
|
85
92
|
before { graph.add_edge('1', '2') }
|
86
|
-
|
93
|
+
|
94
|
+
it { is_expected.to match_array(['1']) }
|
95
|
+
it { is_expected.to be_a(Set) }
|
87
96
|
end
|
88
97
|
|
89
98
|
context 'two edges to' do
|
@@ -93,44 +102,27 @@ describe Nanoc::Int::DirectedGraph do
|
|
93
102
|
end
|
94
103
|
|
95
104
|
it { is_expected.to match_array(%w[1 3]) }
|
105
|
+
it { is_expected.to be_a(Set) }
|
96
106
|
end
|
97
107
|
|
98
108
|
context 'edge from' do
|
99
109
|
before { graph.add_edge('2', '3') }
|
110
|
+
|
100
111
|
it { is_expected.to be_empty }
|
112
|
+
it { is_expected.to be_a(Set) }
|
101
113
|
end
|
102
114
|
end
|
103
115
|
|
104
|
-
describe '#
|
105
|
-
subject { graph.
|
116
|
+
describe '#predecessors_of' do
|
117
|
+
subject { graph.predecessors_of('2') }
|
106
118
|
|
107
|
-
context '
|
108
|
-
|
109
|
-
end
|
119
|
+
context 'requested for non-existant vertex' do
|
120
|
+
subject { graph.predecessors_of('12345') }
|
110
121
|
|
111
|
-
context 'one edge to' do
|
112
|
-
before { graph.add_edge('1', '2') }
|
113
122
|
it { is_expected.to be_empty }
|
123
|
+
it { is_expected.to be_a(Set) }
|
114
124
|
end
|
115
125
|
|
116
|
-
context 'one edge from' do
|
117
|
-
before { graph.add_edge('2', '3') }
|
118
|
-
it { is_expected.to eq(['3']) }
|
119
|
-
end
|
120
|
-
|
121
|
-
context 'two edges from' do
|
122
|
-
before do
|
123
|
-
graph.add_edge('2', '1')
|
124
|
-
graph.add_edge('2', '3')
|
125
|
-
end
|
126
|
-
|
127
|
-
it { is_expected.to match_array(%w[1 3]) }
|
128
|
-
end
|
129
|
-
end
|
130
|
-
|
131
|
-
describe '#predecessors_of' do
|
132
|
-
subject { graph.predecessors_of('2') }
|
133
|
-
|
134
126
|
context 'no predecessors' do
|
135
127
|
before do
|
136
128
|
graph.add_edge('2', '3')
|
@@ -156,34 +148,6 @@ describe Nanoc::Int::DirectedGraph do
|
|
156
148
|
end
|
157
149
|
end
|
158
150
|
|
159
|
-
describe '#successors_of' do
|
160
|
-
subject { graph.successors_of('2') }
|
161
|
-
|
162
|
-
context 'no successors' do
|
163
|
-
before do
|
164
|
-
graph.add_edge('1', '2')
|
165
|
-
end
|
166
|
-
|
167
|
-
it { is_expected.to be_empty }
|
168
|
-
end
|
169
|
-
|
170
|
-
context 'direct predecessor' do
|
171
|
-
before do
|
172
|
-
graph.add_edge('1', '2')
|
173
|
-
graph.add_edge('2', '3')
|
174
|
-
end
|
175
|
-
|
176
|
-
context 'no indirect successors' do
|
177
|
-
it { is_expected.to match_array(['3']) }
|
178
|
-
end
|
179
|
-
|
180
|
-
context 'indirect successors' do
|
181
|
-
before { graph.add_edge('3', '1') }
|
182
|
-
it { is_expected.to match_array(%w[1 2 3]) }
|
183
|
-
end
|
184
|
-
end
|
185
|
-
end
|
186
|
-
|
187
151
|
describe '#inspect' do
|
188
152
|
subject { graph.inspect }
|
189
153
|
|
data/spec/spec_helper.rb
CHANGED
@@ -6,13 +6,11 @@ class Nanoc::Int::DirectedGraphTest < Nanoc::TestCase
|
|
6
6
|
def test_add_edge
|
7
7
|
graph = Nanoc::Int::DirectedGraph.new([1, 2, 3])
|
8
8
|
|
9
|
-
assert_equal [], graph.
|
10
|
-
assert_equal [], graph.predecessors_of(2)
|
9
|
+
assert_equal [], graph.predecessors_of(2).to_a
|
11
10
|
|
12
11
|
graph.add_edge(1, 2)
|
13
12
|
|
14
|
-
assert_equal [
|
15
|
-
assert_equal [1], graph.predecessors_of(2)
|
13
|
+
assert_equal [1], graph.predecessors_of(2).to_a
|
16
14
|
end
|
17
15
|
|
18
16
|
def test_add_edge_with_new_vertices
|
@@ -35,38 +33,20 @@ class Nanoc::Int::DirectedGraphTest < Nanoc::TestCase
|
|
35
33
|
graph.add_edge(3, 1)
|
36
34
|
|
37
35
|
assert_equal [2, 3], graph.direct_predecessors_of(1).sort
|
38
|
-
assert_equal [2, 3], graph.direct_successors_of(1).sort
|
39
36
|
assert_equal [1, 3], graph.direct_predecessors_of(2).sort
|
40
|
-
assert_equal [1, 3], graph.direct_successors_of(2).sort
|
41
37
|
assert_equal [1, 2], graph.direct_predecessors_of(3).sort
|
42
|
-
assert_equal [1, 2], graph.direct_successors_of(3).sort
|
43
38
|
|
44
39
|
graph.delete_edges_to(1)
|
45
40
|
|
46
41
|
assert_equal [], graph.direct_predecessors_of(1).sort
|
47
|
-
assert_equal [2, 3], graph.direct_successors_of(1).sort
|
48
42
|
assert_equal [1, 3], graph.direct_predecessors_of(2).sort
|
49
|
-
assert_equal [3], graph.direct_successors_of(2).sort
|
50
43
|
assert_equal [1, 2], graph.direct_predecessors_of(3).sort
|
51
|
-
assert_equal [2], graph.direct_successors_of(3).sort
|
52
44
|
|
53
45
|
graph.delete_edges_to(2)
|
54
46
|
|
55
47
|
assert_equal [], graph.direct_predecessors_of(1).sort
|
56
|
-
assert_equal [3], graph.direct_successors_of(1).sort
|
57
48
|
assert_equal [], graph.direct_predecessors_of(2).sort
|
58
|
-
assert_equal [3], graph.direct_successors_of(2).sort
|
59
49
|
assert_equal [1, 2], graph.direct_predecessors_of(3).sort
|
60
|
-
assert_equal [], graph.direct_successors_of(3).sort
|
61
|
-
end
|
62
|
-
|
63
|
-
def test_should_return_empty_array_for_nonexistant_vertices
|
64
|
-
graph = Nanoc::Int::DirectedGraph.new([1, 2, 3])
|
65
|
-
|
66
|
-
assert_equal [], graph.direct_predecessors_of(4)
|
67
|
-
assert_equal [], graph.predecessors_of(4)
|
68
|
-
assert_equal [], graph.direct_successors_of(4)
|
69
|
-
assert_equal [], graph.successors_of(4)
|
70
50
|
end
|
71
51
|
|
72
52
|
def test_example
|
data/test/helper.rb
CHANGED
@@ -27,7 +27,7 @@ require 'nanoc/cli'
|
|
27
27
|
Nanoc::CLI.setup
|
28
28
|
|
29
29
|
module Nanoc::TestHelpers
|
30
|
-
LIB_DIR = File.expand_path(
|
30
|
+
LIB_DIR = File.expand_path(__dir__ + '/../lib')
|
31
31
|
|
32
32
|
def disable_nokogiri?
|
33
33
|
ENV.key?('DISABLE_NOKOGIRI')
|
@@ -271,7 +271,7 @@ EOS
|
|
271
271
|
end
|
272
272
|
|
273
273
|
def root_dir
|
274
|
-
File.absolute_path(
|
274
|
+
File.absolute_path(__dir__ + '/..')
|
275
275
|
end
|
276
276
|
end
|
277
277
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nanoc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.8.
|
4
|
+
version: 4.8.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Denis Defreyne
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-08-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: cri
|