This is an automated email from the ASF dual-hosted git repository.
sebb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/whimsy.git
The following commit(s) were added to refs/heads/master by this push:
new e519259 Don't clobber input
e519259 is described below
commit e5192596af4ff7b7b65528fd8a6ec4296f38ad91
Author: Sebb <[email protected]>
AuthorDate: Sat Oct 17 00:20:44 2020 +0100
Don't clobber input
Also provide full yaml for additional checks if needed
---
lib/whimsy/asf/yaml.rb | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/lib/whimsy/asf/yaml.rb b/lib/whimsy/asf/yaml.rb
index 1a95e73..a118c83 100644
--- a/lib/whimsy/asf/yaml.rb
+++ b/lib/whimsy/asf/yaml.rb
@@ -39,17 +39,19 @@ module YamlFile
raise ArgumentError, "Could not find section #{key.inspect}"
end
+ output = content.dup
+
# Create the updated section with the correct indentation
# Use YAML dump to ensure correct syntax; drop the YAML header
- new_section = YAML.dump({key => yield(section)}).sub(/\A---\n/, '')
+ new_section = YAML.dump({key => yield(section, yaml)}).sub(/\A---\n/, '')
# replace the old section with the new one
# assume it is delimited by the key and '...' or another key.
# Keys may be symbols. Only handles top-level key matching.
range = %r{^#{key.inspect}:\s*$.*?(?=^(:?\w+:|\.\.\.)$)}m
- content[range] = new_section
+ output[range] = new_section
- content
+ output
end
# encapsulate updates to a section of a YAML file whilst