nanoc 4.8.0 → 4.8.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ab3b0e2a49c31a0e5209b914287d56489eb2e119
4
- data.tar.gz: 63ed26c7176937deef06fc01a2c7a831983b96ff
3
+ metadata.gz: 8537bc61d500ed5bae70dcae626b5991fd43dea7
4
+ data.tar.gz: 565524a4ffb2733eb6b05fe547c3ee7e2b0788e9
5
5
  SHA512:
6
- metadata.gz: 7294e06953f7be8c6331578429f229b3ff6ca06ba1ac9339de20eb77788f60f45dc5310ee9e212f2d0d375171cbd9b7ad86950d5f57bdbd4c4b84a2fc1ffd569
7
- data.tar.gz: 7dd6820592b64f3e1a84fb655d2e6682d094752c80ac9133bb59aea639379a930d1a72388b9c4038fd414d90fed44058ed1d59f2b61a60bf47304620aa213405
6
+ metadata.gz: b174cadc89845ac6b8e7fec2cea4f9feb4022eef44653a6f505c9eb00d10c59c9ba3fc73d5b2f61cb9a928248fac433944d81e780eb0934dd309939def7ecd2a
7
+ data.tar.gz: 78c42adc2b1bc34501aaae163baffc6ab839b45f81d80430a924cca13d0d3a63573702c0a02bcdce4e788a7a5cf560c5250c09617fa065f1c0cc124086412516
data/NEWS.md CHANGED
@@ -1,8 +1,14 @@
1
1
  # Nanoc news
2
2
 
3
+ ## 4.8.1 (2017-08-06)
4
+
5
+ Enhancements:
6
+
7
+ * Various speed improvements
8
+
3
9
  ## 4.8.0 (2017-07-17)
4
10
 
5
- Featured:
11
+ Features:
6
12
 
7
13
  * Added `asciidoctor` filter (#1199)
8
14
 
@@ -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('b', 'e')
18
+ # graph.add_edge('d', 'e')
17
19
  #
18
- # # Get (direct) successors
19
- # graph.direct_successors_of('a').sort
20
- # # => %w( b )
21
- # graph.successors_of('a').sort
22
- # # => %w( b c d e )
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) successors again
28
- # graph.direct_successors_of('a').sort
29
- # # => %w( b )
30
- # graph.successors_of('a').sort
31
- # # => %w( b e )
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 |v1, _|
57
- direct_successors_of(v1).each do |v2|
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[to].to_a
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 |v1, i1|
177
- direct_successors_of(v1).map { |v2| [@vertices[v2], v2] }.each do |i2, v2|
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.to_a
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
@@ -96,7 +96,7 @@ module Nanoc::CLI
96
96
  @root_command = nil
97
97
 
98
98
  # Add root command
99
- filename = File.dirname(__FILE__) + '/cli/commands/nanoc.rb'
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[File.dirname(__FILE__) + '/cli/commands/*.rb']
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)
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Nanoc
4
4
  # The current Nanoc version.
5
- VERSION = '4.8.0'
5
+ VERSION = '4.8.1'
6
6
  end
@@ -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
- it { is_expected.to eq(['1']) }
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 '#direct_successors_of' do
105
- subject { graph.direct_successors_of('2') }
116
+ describe '#predecessors_of' do
117
+ subject { graph.predecessors_of('2') }
106
118
 
107
- context 'no edges' do
108
- it { is_expected.to be_empty }
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
 
@@ -36,7 +36,7 @@ RSpec.configure do |c|
36
36
  end
37
37
 
38
38
  c.around(:each, chdir: false) do |example|
39
- FileUtils.cd(File.dirname(__FILE__) + '/..') do
39
+ FileUtils.cd(__dir__ + '/..') do
40
40
  example.run
41
41
  end
42
42
  end
@@ -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.successors_of(1)
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 [2], graph.successors_of(1)
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
@@ -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(File.dirname(__FILE__) + '/../lib')
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(File.dirname(__FILE__) + '/..')
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.0
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-07-17 00:00:00.000000000 Z
11
+ date: 2017-08-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cri