Sha256: 6058a342ca59f9d189d5034fc02792f4269f3df14bb90e0ad030f04205c09018
Contents?: true
Size: 645 Bytes
Versions: 16
Compression:
Stored size: 645 Bytes
Contents
# frozen_string_literal: true module Codebreaker module Entities class DataStorage FILE_NAME = 'database/data.yml' def create File.new(FILE_NAME, 'w') File.write(FILE_NAME, [].to_yaml) end def load YAML.safe_load(File.open(FILE_NAME), [Symbol, Time]) if storage_exist? end def save(object) File.open(FILE_NAME, 'w') { |file| file.write(YAML.dump(object)) } end def storage_exist? File.exist?(FILE_NAME) end def save_game_result(object) create unless storage_exist? save(load.push(object)) end end end end
Version data entries
16 entries across 16 versions & 1 rubygems