nanoc-core 4.12.6 → 4.12.8

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
  SHA256:
3
- metadata.gz: d49707fbc3c897e11757663c5d79f8b75349b34ac7e110f2609b59c080214b20
4
- data.tar.gz: d2b88897dd12e0d4cbedbde6a8fde5bcf61613adceb7214589d6f7b3d8fa90fc
3
+ metadata.gz: a29a2064140d04c44df1122dc537ca800a3ed7c20bfb740c4009f3b976067ebb
4
+ data.tar.gz: 6fc3869373babe4c16671b15747d0d3da4b291e4f6434cf1af6e5fbe05c99799
5
5
  SHA512:
6
- metadata.gz: e9c958ab4f52a499a95d483dbea86b8e1e2a0fbe41cddd29a46b13b3dd5c2d95924df6b216798c43cf9565be67084ce4cba19da33ffc7f022b61250f839f1141
7
- data.tar.gz: 1679adcebcdc5380ceac677ad11460db995cd5b8c0491cb484b69c9ae0b6e98aa1a06fb87f662a6653641020120fde2288c8e75e3f94632b422b0d4858d906ef
6
+ metadata.gz: bd1fd013b69ae47c40b8a1c5558729314603ceadabdadf3eb7b117b810988a7f7d777d5f3d6dba9f3e4f899763064c073ddd1e808f7d1e0f8aae8d52dc0c1e43
7
+ data.tar.gz: a11a2202ed08c519e151f097aee47ee16e189a969169fb09ca29162acb99436531007c8c943b6dea892be702454e518376a16253dc9f181069625305e1f09554
@@ -46,16 +46,16 @@ module Nanoc
46
46
  end
47
47
 
48
48
  # contract C::Func[Nanoc::Core::ProcessingAction => C::Any] => self
49
- def each
50
- @actions.each { |a| yield(a) }
49
+ def each(&block)
50
+ @actions.each(&block)
51
51
  self
52
52
  end
53
53
 
54
54
  # contract C::Func[Nanoc::Core::ProcessingAction => C::Any] => self
55
- def map
55
+ def map(&block)
56
56
  self.class.new(
57
57
  @item_rep,
58
- actions: @actions.map { |a| yield(a) },
58
+ actions: @actions.map(&block),
59
59
  )
60
60
  end
61
61
  end
@@ -33,7 +33,7 @@ module Nanoc
33
33
 
34
34
  # @see Object#hash
35
35
  def hash
36
- self.class.hash ^ item.identifier.hash ^ name.hash
36
+ [self.class, item.identifier, name].hash
37
37
  end
38
38
 
39
39
  # @return [Symbol]
@@ -38,16 +38,16 @@ module Nanoc
38
38
  @listener&.to_stop&.call
39
39
  end
40
40
 
41
- def map
42
- self.class.new(enum: @enum.map { |e| yield(e) })
41
+ def map(&block)
42
+ self.class.new(enum: @enum.map(&block))
43
43
  end
44
44
 
45
45
  def to_enum
46
46
  @enum
47
47
  end
48
48
 
49
- def each
50
- @enum.each { |e| yield(e) }
49
+ def each(&block)
50
+ @enum.each(&block)
51
51
  nil
52
52
  end
53
53
  end
@@ -10,8 +10,8 @@ module Nanoc
10
10
  DONE = Object.new
11
11
 
12
12
  contract Nanoc::Core::ItemRep, C::KeywordArgs[is_outdated: C::Bool], C::Func[C::None => C::Any] => C::Any
13
- def run(rep, is_outdated:)
14
- fiber = fiber_for(rep, is_outdated: is_outdated) { yield }
13
+ def run(rep, is_outdated:, &block)
14
+ fiber = fiber_for(rep, is_outdated: is_outdated, &block)
15
15
  while fiber.alive?
16
16
  res = fiber.resume
17
17
 
@@ -84,11 +84,9 @@ module Nanoc
84
84
  outdatedness_store: @outdatedness_store,
85
85
  )
86
86
 
87
- notify_phrase = Nanoc::Core::CompilationPhases::Notify.new(
87
+ Nanoc::Core::CompilationPhases::Notify.new(
88
88
  wrapped: mark_done_phase,
89
89
  )
90
-
91
- notify_phrase
92
90
  end
93
91
  end
94
92
  end
@@ -4,6 +4,8 @@ module Nanoc
4
4
  module Core
5
5
  # @api private
6
6
  class ConfigLoader
7
+ PERMITTED_YAML_CLASSES = [Symbol, Date, Time].freeze
8
+
7
9
  class NoConfigFileFoundError < ::Nanoc::Core::Error
8
10
  def initialize
9
11
  super('No configuration file found')
@@ -54,7 +56,7 @@ module Nanoc
54
56
  end
55
57
 
56
58
  def load_file(filename)
57
- YAML.load_file(filename)
59
+ YAML.safe_load_file(filename, permitted_classes: PERMITTED_YAML_CLASSES)
58
60
  end
59
61
 
60
62
  # @api private
@@ -45,7 +45,7 @@ module Nanoc
45
45
  NANOC_ENV_DEFAULT = 'default'
46
46
 
47
47
  contract C::KeywordArgs[hash: C::Optional[Hash], env_name: C::Maybe[String], dir: C::AbsolutePathString] => C::Any
48
- def initialize(hash: {}, dir:, env_name: nil)
48
+ def initialize(dir:, hash: {}, env_name: nil)
49
49
  @env_name = env_name
50
50
  @wrapped = hash.__nanoc_symbolize_keys_recursively
51
51
  @dir = dir
@@ -136,8 +136,8 @@ module Nanoc
136
136
  end
137
137
 
138
138
  contract C::Func[C::Any, C::Any => C::Any] => self
139
- def each
140
- @wrapped.each { |k, v| yield(k, v) }
139
+ def each(&block)
140
+ @wrapped.each(&block)
141
141
  self
142
142
  end
143
143
 
@@ -6,7 +6,7 @@ module Nanoc
6
6
  class Ignorer
7
7
  include Singleton
8
8
 
9
- def method_missing(*_args) # rubocop:disable Style/MethodMissingSuper
9
+ def method_missing(*_args)
10
10
  self
11
11
  end
12
12
 
@@ -107,7 +107,7 @@ module Nanoc
107
107
 
108
108
  contract C::None => C::Num
109
109
  def hash
110
- self.class.hash ^ identifier.hash
110
+ [self.class, identifier].hash
111
111
  end
112
112
 
113
113
  contract C::Any => C::Bool
@@ -26,7 +26,7 @@ module Nanoc
26
26
 
27
27
  # @see Object#hash
28
28
  def hash
29
- self.class.hash ^ identifier.hash
29
+ [self.class, identifier].hash
30
30
  end
31
31
 
32
32
  # @return [Nanoc::Core::Identifier]
@@ -88,7 +88,7 @@ module Nanoc
88
88
 
89
89
  contract C::None => C::Num
90
90
  def hash
91
- self.class.hash ^ to_s.hash
91
+ [self.class, to_s].hash
92
92
  end
93
93
 
94
94
  contract C::Any => C::Maybe[C::Num]
@@ -149,10 +149,10 @@ module Nanoc
149
149
 
150
150
  extname = File.extname(@string)
151
151
 
152
- if !extname.empty?
153
- @string[0..-extname.size - 1]
154
- else
152
+ if extname.empty?
155
153
  @string
154
+ else
155
+ @string[0..-extname.size - 1]
156
156
  end
157
157
  end
158
158
 
@@ -171,10 +171,10 @@ module Nanoc
171
171
  # The identifier, as string, with all extensions removed
172
172
  def without_exts
173
173
  extname = exts.join('.')
174
- if !extname.empty?
175
- @string[0..-extname.size - 2]
176
- else
174
+ if extname.empty?
177
175
  @string
176
+ else
177
+ @string[0..-extname.size - 2]
178
178
  end
179
179
  end
180
180
 
@@ -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,62 +44,63 @@ 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
- if !acc.useful_to_apply?(rule)
84
- acc
85
- else
84
+ if acc.useful_to_apply?(rule)
86
85
  reason = rule.instance.call(obj, @outdatedness_checker)
87
86
  if reason
88
87
  acc.update(reason)
89
88
  else
90
89
  acc
91
90
  end
91
+ else
92
+ acc
92
93
  end
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
@@ -26,7 +26,7 @@ module Nanoc
26
26
  end
27
27
 
28
28
  def hash
29
- self.class.hash ^ filter_name.hash ^ params.hash
29
+ [self.class, filter_name, params].hash
30
30
  end
31
31
 
32
32
  def ==(other)
@@ -24,7 +24,7 @@ module Nanoc
24
24
  end
25
25
 
26
26
  def hash
27
- self.class.hash ^ layout_identifier.hash ^ params.hash
27
+ [self.class, layout_identifier, params].hash
28
28
  end
29
29
 
30
30
  def ==(other)
@@ -34,7 +34,7 @@ module Nanoc
34
34
  end
35
35
 
36
36
  def hash
37
- self.class.hash ^ snapshot_names.hash ^ paths.hash
37
+ [self.class, snapshot_names, paths].hash
38
38
  end
39
39
 
40
40
  def ==(other)
@@ -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.6'
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.6
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-05-28 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
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
96
  version: '1.5'
97
+ - !ruby/object:Gem::Dependency
98
+ name: psych
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '4.0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '4.0'
97
111
  - !ruby/object:Gem::Dependency
98
112
  name: slow_enumerator_tools
99
113
  requirement: !ruby/object:Gem::Requirement
@@ -294,14 +308,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
294
308
  requirements:
295
309
  - - ">="
296
310
  - !ruby/object:Gem::Version
297
- version: '2.6'
311
+ version: '2.7'
298
312
  required_rubygems_version: !ruby/object:Gem::Requirement
299
313
  requirements:
300
314
  - - ">="
301
315
  - !ruby/object:Gem::Version
302
316
  version: '0'
303
317
  requirements: []
304
- rubygems_version: 3.3.14
318
+ rubygems_version: 3.3.22
305
319
  signing_key:
306
320
  specification_version: 4
307
321
  summary: Core of Nanoc