Sha256: e4431af952183e811e2523f672bfdfc90c5f3d1327c921b92332ae2bb405a951

Contents?: true

Size: 505 Bytes

Versions: 4

Compression:

Stored size: 505 Bytes

Contents

# frozen_string_literal: true

class DataStorage
  FILE_NAME = 'database/data.yml'

  def create
    File.new(FILE_NAME, 'w')
    File.write(FILE_NAME, [].to_yaml)
  end

  def load
    YAML.load(File.open(FILE_NAME), [Menu]) 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

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
codebreaker-yeroshek-0.1.1 lib/app/entities/data_storage.rb
codebreaker_rg-0.1.2 lib/app/entities/data_storage.rb
codebreaker_rg-0.1.1 lib/app/entities/data_storage.rb
codebreaker_rg-0.1.0 lib/app/entities/data_storage.rb