nanoc-core 4.12.7 → 4.12.8

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: 1fb5a347a2a973a7c42b1f85746b5267b43c588bf627c4f813c09c3a23b8e7eb
4
- data.tar.gz: f03ba79aea51348eca0a83c80e3bef8a5853da59981205939b7d417588dd3678
3
+ metadata.gz: a29a2064140d04c44df1122dc537ca800a3ed7c20bfb740c4009f3b976067ebb
4
+ data.tar.gz: 6fc3869373babe4c16671b15747d0d3da4b291e4f6434cf1af6e5fbe05c99799
5
5
  SHA512:
6
- metadata.gz: '0211852d5d7069d0dec63609db20a2cf533ba167e71ab08e195e333abea2cb17ecce34b05c4c65cd0be84c1726389caae8f02313188641a980e1aa6622f47619'
7
- data.tar.gz: d3f7d023ce5855b2e2b67c2e49132b60aaec1f8cc71bf7163b2d1a2492304fccf932a2252e0ea1546c4694a83168395195dae444c530ad641c37d5f45e0a9673
6
+ metadata.gz: bd1fd013b69ae47c40b8a1c5558729314603ceadabdadf3eb7b117b810988a7f7d777d5f3d6dba9f3e4f899763064c073ddd1e808f7d1e0f8aae8d52dc0c1e43
7
+ data.tar.gz: a11a2202ed08c519e151f097aee47ee16e189a969169fb09ca29162acb99436531007c8c943b6dea892be702454e518376a16253dc9f181069625305e1f09554
@@ -4,13 +4,36 @@ module Nanoc
4
4
  module Core
5
5
  # @api private
6
6
  class Instrumentor
7
+ @enabled = false
8
+
9
+ def self.enable
10
+ if block_given?
11
+ begin
12
+ enable
13
+ yield
14
+ ensure
15
+ disable
16
+ end
17
+ else
18
+ @enabled = true
19
+ end
20
+ end
21
+
22
+ def self.disable
23
+ @enabled = false
24
+ end
25
+
7
26
  def self.call(key, *args)
8
- stopwatch = DDMetrics::Stopwatch.new
9
- stopwatch.start
10
- yield
11
- ensure
12
- stopwatch.stop
13
- Nanoc::Core::NotificationCenter.post(key, stopwatch.duration, *args)
27
+ return yield unless @enabled
28
+
29
+ begin
30
+ stopwatch = DDMetrics::Stopwatch.new
31
+ stopwatch.start
32
+ yield
33
+ ensure
34
+ stopwatch.stop
35
+ Nanoc::Core::NotificationCenter.post(key, stopwatch.duration, *args)
36
+ end
14
37
  end
15
38
  end
16
39
  end
@@ -7,9 +7,7 @@ module Nanoc
7
7
  # @api private
8
8
  class OutdatednessChecker
9
9
  class Basic
10
- prepend MemoWise
11
-
12
- # include Nanoc::Core::ContractsSupport
10
+ include Nanoc::Core::ContractsSupport
13
11
 
14
12
  Rules = Nanoc::Core::OutdatednessRules
15
13
 
@@ -46,38 +44,41 @@ module Nanoc
46
44
  Rules::LayoutCollectionExtended,
47
45
  ].freeze
48
46
 
49
- # C_OBJ_MAYBE_REP = C::Or[Nanoc::Core::Item, Nanoc::Core::ItemRep, Nanoc::Core::Configuration, Nanoc::Core::Layout, Nanoc::Core::ItemCollection, Nanoc::Core::LayoutCollection]
47
+ C_OBJ_MAYBE_REP = C::Or[Nanoc::Core::Item, Nanoc::Core::ItemRep, Nanoc::Core::Configuration, Nanoc::Core::Layout, Nanoc::Core::ItemCollection, Nanoc::Core::LayoutCollection]
50
48
 
51
- # contract C::KeywordArgs[outdatedness_checker: OutdatednessChecker, reps: Nanoc::Core::ItemRepRepo] => C::Any
49
+ contract C::KeywordArgs[outdatedness_checker: OutdatednessChecker, reps: Nanoc::Core::ItemRepRepo] => C::Any
52
50
  def initialize(outdatedness_checker:, reps:)
53
51
  @outdatedness_checker = outdatedness_checker
54
52
  @reps = reps
53
+
54
+ # Memoize
55
+ @_outdatedness_status_for = {}
55
56
  end
56
57
 
57
- # contract C_OBJ_MAYBE_REP => C::Maybe[Nanoc::Core::OutdatednessStatus]
58
+ contract C_OBJ_MAYBE_REP => C::Maybe[Nanoc::Core::OutdatednessStatus]
58
59
  def outdatedness_status_for(obj)
59
- case obj
60
- when Nanoc::Core::ItemRep
61
- apply_rules(RULES_FOR_ITEM_REP, obj)
62
- when Nanoc::Core::Item
63
- apply_rules_multi(RULES_FOR_ITEM_REP, @reps[obj])
64
- when Nanoc::Core::Layout
65
- apply_rules(RULES_FOR_LAYOUT, obj)
66
- when Nanoc::Core::Configuration
67
- apply_rules(RULES_FOR_CONFIG, obj)
68
- when Nanoc::Core::ItemCollection
69
- apply_rules(RULES_FOR_ITEM_COLLECTION, obj)
70
- when Nanoc::Core::LayoutCollection
71
- apply_rules(RULES_FOR_LAYOUT_COLLECTION, obj)
72
- else
73
- raise Nanoc::Core::Errors::InternalInconsistency, "do not know how to check outdatedness of #{obj.inspect}"
74
- end
60
+ @_outdatedness_status_for[obj] ||=
61
+ case obj
62
+ when Nanoc::Core::ItemRep
63
+ apply_rules(RULES_FOR_ITEM_REP, obj)
64
+ when Nanoc::Core::Item
65
+ apply_rules_multi(RULES_FOR_ITEM_REP, @reps[obj])
66
+ when Nanoc::Core::Layout
67
+ apply_rules(RULES_FOR_LAYOUT, obj)
68
+ when Nanoc::Core::Configuration
69
+ apply_rules(RULES_FOR_CONFIG, obj)
70
+ when Nanoc::Core::ItemCollection
71
+ apply_rules(RULES_FOR_ITEM_COLLECTION, obj)
72
+ when Nanoc::Core::LayoutCollection
73
+ apply_rules(RULES_FOR_LAYOUT_COLLECTION, obj)
74
+ else
75
+ raise Nanoc::Core::Errors::InternalInconsistency, "do not know how to check outdatedness of #{obj.inspect}"
76
+ end
75
77
  end
76
- memo_wise :outdatedness_status_for
77
78
 
78
79
  private
79
80
 
80
- # contract C::ArrayOf[Class], C_OBJ_MAYBE_REP, Nanoc::Core::OutdatednessStatus => C::Maybe[Nanoc::Core::OutdatednessStatus]
81
+ contract C::ArrayOf[Class], C_OBJ_MAYBE_REP, Nanoc::Core::OutdatednessStatus => C::Maybe[Nanoc::Core::OutdatednessStatus]
81
82
  def apply_rules(rules, obj, status = Nanoc::Core::OutdatednessStatus.new)
82
83
  rules.inject(status) do |acc, rule|
83
84
  if acc.useful_to_apply?(rule)
@@ -93,15 +94,13 @@ module Nanoc
93
94
  end
94
95
  end
95
96
 
96
- # contract C::ArrayOf[Class], C::ArrayOf[C_OBJ_MAYBE_REP] => C::Maybe[Nanoc::Core::OutdatednessStatus]
97
+ contract C::ArrayOf[Class], C::ArrayOf[C_OBJ_MAYBE_REP] => C::Maybe[Nanoc::Core::OutdatednessStatus]
97
98
  def apply_rules_multi(rules, objs)
98
99
  objs.inject(Nanoc::Core::OutdatednessStatus.new) { |acc, elem| apply_rules(rules, elem, acc) }
99
100
  end
100
101
  end
101
102
 
102
- prepend MemoWise
103
-
104
- # include Nanoc::Core::ContractsSupport
103
+ include Nanoc::Core::ContractsSupport
105
104
 
106
105
  attr_reader :checksum_store
107
106
  attr_reader :checksums
@@ -112,11 +111,11 @@ module Nanoc
112
111
 
113
112
  Reasons = Nanoc::Core::OutdatednessReasons
114
113
 
115
- # C_OBJ = C::Or[Nanoc::Core::Item, Nanoc::Core::ItemRep, Nanoc::Core::Configuration, Nanoc::Core::Layout, Nanoc::Core::ItemCollection]
116
- # C_ITEM_OR_REP = C::Or[Nanoc::Core::Item, Nanoc::Core::ItemRep]
117
- # C_ACTION_SEQUENCES = C::HashOf[C_OBJ => Nanoc::Core::ActionSequence]
114
+ C_OBJ = C::Or[Nanoc::Core::Item, Nanoc::Core::ItemRep, Nanoc::Core::Configuration, Nanoc::Core::Layout, Nanoc::Core::ItemCollection]
115
+ C_ITEM_OR_REP = C::Or[Nanoc::Core::Item, Nanoc::Core::ItemRep]
116
+ C_ACTION_SEQUENCES = C::HashOf[C_OBJ => Nanoc::Core::ActionSequence]
118
117
 
119
- # contract C::KeywordArgs[site: Nanoc::Core::Site, checksum_store: Nanoc::Core::ChecksumStore, checksums: Nanoc::Core::ChecksumCollection, dependency_store: Nanoc::Core::DependencyStore, action_sequence_store: Nanoc::Core::ActionSequenceStore, action_sequences: C_ACTION_SEQUENCES, reps: Nanoc::Core::ItemRepRepo] => C::Any
118
+ contract C::KeywordArgs[site: Nanoc::Core::Site, checksum_store: Nanoc::Core::ChecksumStore, checksums: Nanoc::Core::ChecksumCollection, dependency_store: Nanoc::Core::DependencyStore, action_sequence_store: Nanoc::Core::ActionSequenceStore, action_sequences: C_ACTION_SEQUENCES, reps: Nanoc::Core::ItemRepRepo] => C::Any
120
119
  def initialize(site:, checksum_store:, checksums:, dependency_store:, action_sequence_store:, action_sequences:, reps:)
121
120
  @site = site
122
121
  @checksum_store = checksum_store
@@ -133,12 +132,12 @@ module Nanoc
133
132
  @action_sequences.fetch(rep)
134
133
  end
135
134
 
136
- # contract C_OBJ => C::Bool
135
+ contract C_OBJ => C::Bool
137
136
  def outdated?(obj)
138
137
  outdatedness_reasons_for(obj).any?
139
138
  end
140
139
 
141
- # contract C_OBJ => C::IterOf[Reasons::Generic]
140
+ contract C_OBJ => C::IterOf[Reasons::Generic]
142
141
  def outdatedness_reasons_for(obj)
143
142
  reasons = basic.outdatedness_status_for(obj).reasons
144
143
  if reasons.any?
@@ -152,12 +151,12 @@ module Nanoc
152
151
 
153
152
  private
154
153
 
155
- # contract C::None => Basic
154
+ contract C::None => Basic
156
155
  def basic
157
156
  @_basic ||= Basic.new(outdatedness_checker: self, reps: @reps)
158
157
  end
159
158
 
160
- # contract C_OBJ, Hamster::Set => C::Bool
159
+ contract C_OBJ, Hamster::Set => C::Bool
161
160
  def outdated_due_to_dependencies?(obj, processed = Hamster::Set.new)
162
161
  # Convert from rep to item if necessary
163
162
  obj = obj.item if obj.is_a?(Nanoc::Core::ItemRep)
@@ -189,7 +188,7 @@ module Nanoc
189
188
  is_outdated
190
189
  end
191
190
 
192
- # contract Nanoc::Core::Dependency => C::Bool
191
+ contract Nanoc::Core::Dependency => C::Bool
193
192
  def dependency_causes_outdatedness?(dependency)
194
193
  return true if dependency.from.nil?
195
194
 
@@ -6,11 +6,31 @@ module Nanoc
6
6
  class NotWritten < Nanoc::Core::OutdatednessRule
7
7
  affects_props :raw_content, :attributes, :compiled_content, :path
8
8
 
9
- def apply(obj, _outdatedness_checker)
10
- if obj.raw_paths.values.flatten.compact.any? { |fn| !File.file?(fn) }
9
+ def apply(obj, outdatedness_checker)
10
+ if obj.raw_paths.values.flatten.compact.any? { |fn| !exist?(fn, outdatedness_checker) }
11
11
  Nanoc::Core::OutdatednessReasons::NotWritten
12
12
  end
13
13
  end
14
+
15
+ private
16
+
17
+ def exist?(fn, outdatedness_checker)
18
+ all(outdatedness_checker).include?(fn)
19
+ end
20
+
21
+ def all(outdatedness_checker)
22
+ # NOTE: Cached per outdatedness checker, so that unrelated invocations
23
+ # later on don’t reuse an old cache.
24
+
25
+ @all ||= {}
26
+ @all[outdatedness_checker] ||= Set.new(
27
+ Dir.glob("#{site_root(outdatedness_checker)}/**/*", File::FNM_DOTMATCH),
28
+ )
29
+ end
30
+
31
+ def site_root(outdatedness_checker)
32
+ outdatedness_checker.site.config.output_dir
33
+ end
14
34
  end
15
35
  end
16
36
  end
@@ -81,7 +81,7 @@ module Nanoc
81
81
  return unless File.file?(filename)
82
82
 
83
83
  begin
84
- pstore.transaction do
84
+ pstore.transaction(true) do
85
85
  return if pstore[:version] != version
86
86
 
87
87
  self.data = pstore[:data]
@@ -42,9 +42,8 @@ module Nanoc
42
42
  # @return [void]
43
43
  def cleanup(prefix)
44
44
  path = File.join(@root_dir, prefix)
45
- if File.exist?(path)
46
- FileUtils.rm_rf(path)
47
- end
45
+
46
+ FileUtils.rm_rf(path)
48
47
 
49
48
  @counts.delete(prefix)
50
49
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Nanoc
4
4
  module Core
5
- VERSION = '4.12.7'
5
+ VERSION = '4.12.8'
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.7
4
+ version: 4.12.8
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-06-06 00:00:00.000000000 Z
11
+ date: 2022-10-03 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.15
318
+ rubygems_version: 3.3.22
319
319
  signing_key:
320
320
  specification_version: 4
321
321
  summary: Core of Nanoc