lib/relaton/index/file_io.rb in relaton-index-0.2.0 vs lib/relaton/index/file_io.rb in relaton-index-0.2.1

- old
+ new

@@ -9,14 +9,16 @@ attr_reader :url # # Initialize FileIO # - # @param [String] dir local directory in ~/.relaton to store index - # @param [String, Boolean, nil] url git repository URL to fetch index from - # (if not exists, or older than 24 hours) or nil if index is used to - # index files + # @param [String] dir falvor specific local directory in ~/.relaton to store index + # @param [String, Boolean, nil] url + # if String then the URL is used to fetch an index from a Git repository + # and save it to the storage (if not exists, or older than 24 hours) + # if true then the index is read from the storage (used to remove index file) + # if nil then the fiename is used to read and write file (used to create indes in GH actions) # def initialize(dir, url, filename) @dir = dir @url = url @filename = filename @@ -24,21 +26,21 @@ # # If url is String, check if index file exists and is not older than 24 # hours. If not, fetch index from external repository and save it to # storage. - # If url is true, remove index from storage. - # If url is nil, read index from file. + # If url is true, read index from path to local file. + # If url is nil, read index from filename. # # @return [Array<Hash>] index # def read case url when String check_file || fetch_and_save else - read_file + read_file || [] end end def file @file ||= url ? path_to_local_file : @filename @@ -70,12 +72,13 @@ # # @return [Array<Hash>] index # def read_file yaml = Index.config.storage.read(file) - return [] unless yaml + return unless yaml YAML.safe_load yaml, permitted_classes: [Symbol] + rescue Psych::SyntaxError end # # Fetch index from external repository and save it to storage #