nanoc-core 4.12.9 → 4.12.10

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 835f6e4a74f07183143caa0c2d27f304fa5a712c3231dddc2dd28974f714b117
4
- data.tar.gz: 71331c08284b2f0da1b6410c8a5c17230efa1606640c1ca7e8724fb97e037951
3
+ metadata.gz: 3365fa09f4ff20a16df20f260562fca8c64342098ba70b4547dc38580204ea2e
4
+ data.tar.gz: 132a480e5593d19bb6c1802f6f740e3ed1d081eb88f0178fbde311d9a4e52cc0
5
5
  SHA512:
6
- metadata.gz: 1c3b6430105aab73a5e9efff550b3519bd3e19cf99cb9b70f7a3b42916fd48becc091ea7325740673936373650e0d2950f986e507128aa1a7156f0e95bbb1520
7
- data.tar.gz: 24ef14012f2ed47f9dd77f885601c395b58fb4d50fb61afa2196fedeecac2571d3702ad87f0e7d80d8806a07b6712364774cf6012650595f4a0cae072e85353e
6
+ metadata.gz: 5c0190dbbad1225882d5b76891e80f45cf5e02238c6f6418071d9e8968e82cdd0263099eb5a71963b179238fb57a86f53ef7f7677592299c61cc6197be6b5dd9
7
+ data.tar.gz: 13424fbb1cc81c95e471a8ba99f172d24b6f33b1e9220a50773ed32554f5577622db7d63825734b04254e33c624b2d382b16ced1628952f5cee7e6429d96e57a
@@ -9,6 +9,8 @@ module Nanoc
9
9
 
10
10
  def initialize(checksums)
11
11
  @checksums = checksums
12
+
13
+ @_attribute_checksums = {}
12
14
  end
13
15
 
14
16
  contract c_obj => C::Maybe[String]
@@ -23,7 +25,7 @@ module Nanoc
23
25
 
24
26
  contract c_obj => C::Maybe[C::HashOf[Symbol, String]]
25
27
  def attributes_checksum_for(obj)
26
- @checksums[[obj.reference, :each_attribute]]
28
+ @_attribute_checksums[obj] ||= @checksums[[obj.reference, :each_attribute]]
27
29
  end
28
30
 
29
31
  def to_h
@@ -21,6 +21,8 @@ module Nanoc
21
21
  @objects = objects
22
22
 
23
23
  @checksums = {}
24
+
25
+ invalidate_memoization
24
26
  end
25
27
 
26
28
  contract c_obj => C::Maybe[String]
@@ -50,7 +52,7 @@ module Nanoc
50
52
 
51
53
  contract c_obj => C::Maybe[C::HashOf[Symbol, String]]
52
54
  def attributes_checksum_for(obj)
53
- @checksums[[obj.reference, :each_attribute]]
55
+ @_attribute_checksums[obj] ||= @checksums[[obj.reference, :each_attribute]]
54
56
  end
55
57
 
56
58
  protected
@@ -60,6 +62,8 @@ module Nanoc
60
62
  end
61
63
 
62
64
  def data=(new_data)
65
+ invalidate_memoization
66
+
63
67
  references = Set.new(@objects.map(&:reference))
64
68
 
65
69
  @checksums = {}
@@ -69,6 +73,12 @@ module Nanoc
69
73
  end
70
74
  end
71
75
  end
76
+
77
+ private
78
+
79
+ def invalidate_memoization
80
+ @_attribute_checksums = {}
81
+ end
72
82
  end
73
83
  end
74
84
  end
@@ -111,7 +111,7 @@ module Nanoc
111
111
  def raw_content?
112
112
  case @raw_content
113
113
  when Set
114
- @raw_content.any?
114
+ !@raw_content.empty?
115
115
  else
116
116
  @raw_content
117
117
  end
@@ -121,7 +121,7 @@ module Nanoc
121
121
  def attributes?
122
122
  case @attributes
123
123
  when Set
124
- @attributes.any?
124
+ !@attributes.empty?
125
125
  else
126
126
  @attributes
127
127
  end
@@ -71,12 +71,7 @@ module Nanoc
71
71
  Nanoc::Core::Dependency.new(
72
72
  other_object,
73
73
  object,
74
- Nanoc::Core::DependencyProps.new(
75
- raw_content: props.fetch(:raw_content, false),
76
- attributes: props.fetch(:attributes, false),
77
- compiled_content: props.fetch(:compiled_content, false),
78
- path: props.fetch(:path, false),
79
- ),
74
+ props,
80
75
  )
81
76
  end
82
77
  end
@@ -192,15 +187,22 @@ module Nanoc
192
187
  refs.map { |r| ref2obj(r) }
193
188
  end
194
189
 
195
- # TODO: Return not a Hash, but a DependencyProps instead
196
190
  def props_for(from, to)
197
191
  props = @graph.props_for(obj2ref(from), obj2ref(to))
198
-
199
- if props&.active&.any?
200
- props.to_h
201
- else
202
- { raw_content: true, attributes: true, compiled_content: true, path: true }
203
- end
192
+ return props if props
193
+
194
+ # This is for backwards compatibility, in case there are no dependency
195
+ # props available yet. Pretend everything is set to `true`; it’ll be
196
+ # recompiled and correct props will be available in the next run.
197
+ #
198
+ # NOTE: This isn’t covered by tests, yet. (Not trivial to test because
199
+ # it’s not a condition that can arise in the current Nanoc version.)
200
+ Nanoc::Core::DependencyProps.new(
201
+ raw_content: true,
202
+ attributes: true,
203
+ compiled_content: true,
204
+ path: true,
205
+ )
204
206
  end
205
207
 
206
208
  def data
@@ -49,6 +49,10 @@ module Nanoc
49
49
  @checksum_data = checksum_data
50
50
  @content_checksum_data = content_checksum_data
51
51
  @attributes_checksum_data = attributes_checksum_data
52
+
53
+ # Precalculate for performance
54
+ @hash = [self.class, identifier].hash
55
+ reference
52
56
  end
53
57
 
54
58
  # @return [Hash]
@@ -107,7 +111,7 @@ module Nanoc
107
111
 
108
112
  contract C::None => C::Num
109
113
  def hash
110
- [self.class, identifier].hash
114
+ @hash
111
115
  end
112
116
 
113
117
  contract C::Any => C::Bool
@@ -4,7 +4,7 @@ module Nanoc
4
4
  module Core
5
5
  class Item < ::Nanoc::Core::Document
6
6
  def reference
7
- "item:#{identifier}"
7
+ @_reference ||= "item:#{identifier}"
8
8
  end
9
9
  end
10
10
  end
@@ -4,7 +4,7 @@ module Nanoc
4
4
  module Core
5
5
  class Layout < ::Nanoc::Core::Document
6
6
  def reference
7
- "layout:#{identifier}"
7
+ @_reference ||= "layout:#{identifier}"
8
8
  end
9
9
  end
10
10
  end
@@ -26,13 +26,7 @@ module Nanoc
26
26
  #
27
27
  # @see Hash#[]=
28
28
  def []=(key, value)
29
- disallowed_value_classes = Set.new([
30
- Nanoc::Core::Item,
31
- Nanoc::Core::Layout,
32
- Nanoc::Core::CompilationItemView,
33
- Nanoc::Core::LayoutView,
34
- ])
35
- if disallowed_value_classes.include?(value.class)
29
+ if disallowed_value_class?(value.class)
36
30
  raise DisallowedAttributeValueError.new(value)
37
31
  end
38
32
 
@@ -55,6 +49,21 @@ module Nanoc
55
49
  hash.each { |k, v| _unwrap.set_attribute(k, v) }
56
50
  self
57
51
  end
52
+
53
+ private
54
+
55
+ def disallowed_value_class?(klass)
56
+ # NOTE: We’re explicitly disabling Style/MultipleComparison, because
57
+ # the suggested alternative (Array#include?) carries a measurable
58
+ # performance penatly.
59
+ #
60
+ # rubocop:disable Style/MultipleComparison
61
+ klass == Nanoc::Core::Item ||
62
+ klass == Nanoc::Core::Layout ||
63
+ klass == Nanoc::Core::CompilationItemView ||
64
+ klass == Nanoc::Core::LayoutView
65
+ # rubocop:enable Style/MultipleComparison
66
+ end
58
67
  end
59
68
  end
60
69
  end
@@ -196,7 +196,7 @@ module Nanoc
196
196
  active = status.props.active & dependency.props.active
197
197
  active.delete(:attributes) if attributes_unaffected?(status, dependency)
198
198
 
199
- active.any?
199
+ !active.empty?
200
200
  end
201
201
  end
202
202
 
@@ -269,23 +269,19 @@ module Nanoc
269
269
 
270
270
  new_object_checksums = checksums.attributes_checksum_for(object)
271
271
 
272
- # Ignore any attribute not mentioned in the dependency
273
- old_object_checksums = old_object_checksums.select { |k, _v| dep_checksums.key?(k) }
274
- new_object_checksums = new_object_checksums.select { |k, _v| dep_checksums.key?(k) }
275
-
276
272
  dep_checksums.any? do |key, dep_value|
277
273
  # Get old and new checksum for this particular attribute
278
274
  old_value = old_object_checksums[key]
279
275
  new_value = new_object_checksums[key]
280
276
 
281
- # If either the old or new vale match the value in the dependency,
282
- # then a potential change is relevant to us, and can cause
283
- # outdatedness.
284
- is_match = [old_value, new_value].include?(dep_value)
285
-
286
- is_changed = old_value != new_value
277
+ # If the old and new checksums are identical, then the attribute is
278
+ # unchanged and can’t cause outdatedness.
279
+ next false unless old_value != new_value
287
280
 
288
- is_match && is_changed
281
+ # We already know that the old value and new value are different.
282
+ # This attribute will cause outdatedness if either of those
283
+ # checksums is identical to the one in the prop.
284
+ old_value == dep_value || new_value == dep_value
289
285
  end
290
286
  end
291
287
  end
@@ -23,11 +23,39 @@ module Nanoc
23
23
  end
24
24
 
25
25
  def self.affects_props(*names)
26
- @affected_props = Set.new(names)
26
+ @affects_raw_content = false
27
+ @affects_attributes = false
28
+ @affects_compiled_content = false
29
+ @affects_path = false
30
+
31
+ names.each do |name|
32
+ case name
33
+ when :raw_content
34
+ @affects_raw_content = true
35
+ when :attributes
36
+ @affects_attributes = true
37
+ when :compiled_content
38
+ @affects_compiled_content = true
39
+ when :path
40
+ @affects_path = true
41
+ end
42
+ end
43
+ end
44
+
45
+ def self.affects_raw_content?
46
+ @affects_raw_content
47
+ end
48
+
49
+ def self.affects_attributes?
50
+ @affects_attributes
51
+ end
52
+
53
+ def self.affects_compiled_content?
54
+ @affects_compiled_content
27
55
  end
28
56
 
29
- def self.affected_props
30
- @affected_props
57
+ def self.affects_path?
58
+ @affects_path
31
59
  end
32
60
  end
33
61
  end
@@ -13,7 +13,12 @@ module Nanoc
13
13
  end
14
14
 
15
15
  def useful_to_apply?(rule)
16
- (rule.affected_props - @props.active).any?
16
+ return true if rule.affects_raw_content? && !@props.raw_content?
17
+ return true if rule.affects_attributes? && !@props.attributes?
18
+ return true if rule.affects_compiled_content? && !@props.compiled_content?
19
+ return true if rule.affects_path? && !@props.path?
20
+
21
+ false
17
22
  end
18
23
 
19
24
  def update(reason)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Nanoc
4
4
  module Core
5
- VERSION = '4.12.9'
5
+ VERSION = '4.12.10'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nanoc-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.12.9
4
+ version: 4.12.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Denis Defreyne
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-10-08 00:00:00.000000000 Z
11
+ date: 2022-10-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -315,7 +315,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
315
315
  - !ruby/object:Gem::Version
316
316
  version: '0'
317
317
  requirements: []
318
- rubygems_version: 3.3.22
318
+ rubygems_version: 3.3.24
319
319
  signing_key:
320
320
  specification_version: 4
321
321
  summary: Core of Nanoc