Sha256: 292cd5b4e67f6048dfe811489b51415fb0fc2a83daa67f6edd6c5a2e2f2293d5

Contents?: true

Size: 437 Bytes

Versions: 1

Compression:

Stored size: 437 Bytes

Contents

require 'yaml'
require 'fileutils'

module FileWorker
  extend self

  BACKUP_FILE_NAME = 'library_backup.yaml'.freeze
  
  def write_backup(raw_yaml)
    create_data_dir_if_not_exist
    File.open("data/#{BACKUP_FILE_NAME}", 'w+') do |f|
      f.write(raw_yaml)
    end
  end
  
  def read_backup
    YAML.load_file("data/#{BACKUP_FILE_NAME}")
  end

  private

  def create_data_dir_if_not_exist
    FileUtils.mkdir_p('data')
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
bokov_library-1.0.0 lib/file_worker.rb