Module: SaveFile
- Included in:
- SaveIdHashToFile, SaveNullifiedRelsToFile
- Defined in:
- lib/backup/save_file.rb
Instance Method Summary collapse
- #current_time_for_subfolder ⇒ Object
- #ensure_path(file_path) ⇒ Object
- #folder_path(file_path) ⇒ Object
- #full_file_path(file_path) ⇒ Object
-
#save_file(file_path, content) ⇒ Object
rubocop:disable Metrics/MethodLength.
Instance Method Details
#current_time_for_subfolder ⇒ Object
22 23 24 |
# File 'lib/backup/save_file.rb', line 22 def current_time_for_subfolder Time.now.to_s.parameterize.underscore end |
#ensure_path(file_path) ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/backup/save_file.rb', line 26 def ensure_path(file_path) path = folder_path(file_path) unless File.directory?(path) FileUtils.mkdir_p(path) end end |
#folder_path(file_path) ⇒ Object
38 39 40 41 42 |
# File 'lib/backup/save_file.rb', line 38 def folder_path(file_path) result = full_file_path(file_path).split('/') result.pop result.join('/') end |
#full_file_path(file_path) ⇒ Object
34 35 36 |
# File 'lib/backup/save_file.rb', line 34 def full_file_path(file_path) "#{@config.files_location}/#{file_path}" end |
#save_file(file_path, content) ⇒ Object
rubocop:disable Metrics/MethodLength
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/backup/save_file.rb', line 4 def save_file(file_path, content) # rubocop:disable Metrics/MethodLength return true if @config.dry_run saved = false begin ensure_path(file_path) File.open(full_file_path(file_path), 'w') do |file| file.write(content) file.close saved = true end rescue => e print "Failed to save #{file_path}, error: #{e.inspect}\n" end saved end |