lib/usps_flags/helpers.rb in usps_flags-0.3.13 vs lib/usps_flags/helpers.rb in usps_flags-0.3.14

- old
+ new

@@ -106,17 +106,30 @@ messages ensure log_file.close if log_file.is_a?(File) end + # Ensures the directory for the specified path exists. + # + # This should never need to be called directly. + # @private + def ensure_dir_for_file(path) + return false if path.nil? || path.empty? || !path.scan("/") + + dirs = path.split("/") + dirs.pop + ::FileUtils.mkdir_p(dirs.join("/")).first + end + # Prints output to the console or saves to a file, then returns the generated data. # # This should never need to be called directly. # @private def output(svg, outfile: nil) if outfile.nil? puts svg, "\n" elsif outfile != "" + ensure_dir_for_file(outfile) f = ::File.new(outfile, "w+") f.write(svg) f.close end svg