You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@whimsical.apache.org by se...@apache.org on 2020/10/16 12:10:39 UTC

[whimsy] branch master updated: Enable Symbols; don't suppress errors

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 98819fd  Enable Symbols; don't suppress errors
98819fd is described below

commit 98819fd45e9348235ef968259f31a2f5b262d7bf
Author: Sebb <se...@apache.org>
AuthorDate: Fri Oct 16 13:10:28 2020 +0100

    Enable Symbols; don't suppress errors
---
 lib/whimsy/asf/yaml.rb | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/lib/whimsy/asf/yaml.rb b/lib/whimsy/asf/yaml.rb
index 6497fb8..995aa2a 100644
--- a/lib/whimsy/asf/yaml.rb
+++ b/lib/whimsy/asf/yaml.rb
@@ -10,13 +10,16 @@ module YamlFile
 
   #
   # encapsulate updates to a YAML file
-  # opens the file for exclusive access with an exclusive lock
+  # opens the file for exclusive access with an exclusive lock,
+  # creating the file if necessary
   # Yields the parsed YAML to the block, and writes the updated
   # data to the file
+  # The args are passed to YAML.safe_load, and default to [Symbol]
   def self.update(yaml_file, *args)
-    File.open(yaml_file, File::RDWR|File::CREAT, 0644) do |file|
+    args << [Symbol] if args.empty?
+    File.open(yaml_file, File::RDWR|File::CREAT, 0o644) do |file|
       file.flock(File::LOCK_EX)
-      yaml = YAML.safe_load(file.read, *args) || {} rescue {}
+      yaml = YAML.safe_load(file.read, *args) || {}
       yield yaml
       file.rewind
       file.write YAML.dump(yaml)
@@ -29,10 +32,12 @@ module YamlFile
   # Opens the file read-only, with a shared lock, and parses the YAML
   # This is yielded to the block (if provided), whilst holding the lock
   # Otherwise the YAML is returned to the caller, and the lock is released
+  # The args are passed to YAML.safe_load, and default to [Symbol]
   def self.read(yaml_file, *args)
+    args << [Symbol] if args.empty?
     File.open(yaml_file, File::RDONLY) do |file|
       file.flock(File::LOCK_SH)
-      yaml = YAML.safe_load(file.read,*args) || {} rescue {}
+      yaml = YAML.safe_load(file.read, *args)
       if block_given?
         yield yaml
       else
@@ -51,4 +56,4 @@ if __FILE__ == $0
     p yaml
   end
   p YamlFile.read(file)
-end
\ No newline at end of file
+end