# frozen_string_literal: true module Codebreaker module Storage FILE_PATH = 'lib/data/data.yml' def save(data) create_storage unless storage_exist? File.open(FILE_PATH, 'w') { |file| file.write data.to_yaml } end def restore_storage storage_exist? ? YAML.load_stream(File.open(FILE_PATH)) : [] end private def storage_exist? File.exist? FILE_PATH end def create_storage File.new(FILE_PATH, 'w+') end end end