Sha256: 9f40a32b9cddee55fbf9ceab55eb5d09c75d5f642036f984770b4c979805e482

Contents?: true

Size: 632 Bytes

Versions: 4

Compression:

Stored size: 632 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.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
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
codebreaker-yeroshek-0.1.5 lib/codebreaker/entities/data_storage.rb
codebreaker-yeroshek-0.1.4 lib/codebreaker/entities/data_storage.rb
codebreaker-yeroshek-0.1.3 lib/codebreaker/entities/data_storage.rb
codebreaker-yeroshek-0.1.2 lib/codebreaker/entities/data_storage.rb