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

Version Path
codebreaker_marian-0.3.0 lib/codebreaker_marian/entities/data_storage.rb
codebreaker_marian-0.2.9 lib/codebreaker_marian/entities/data_storage.rb
codebreaker_marian-0.2.8 lib/codebreaker_marian/entities/data_storage.rb
codebreaker_marian-0.2.7 lib/codebreaker_marian/entities/data_storage.rb
codebreaker_marian-0.2.6 lib/codebreaker_marian/entities/data_storage.rb
codebreaker_marian-0.2.5 lib/codebreaker_marian/entities/data_storage.rb
codebreaker_marian-0.2.4 lib/codebreaker_marian/entities/data_storage.rb
codebreaker_marian-0.2.3 lib/codebreaker_marian/entities/data_storage.rb
codebreaker_marian-0.2.2 lib/codebreaker_marian/entities/data_storage.rb
codebreaker_marian-0.2.1 lib/codebreaker_marian/entities/data_storage.rb
codebreaker_marian-0.2.0 lib/codebreaker_marian/entities/data_storage.rb
codebreaker_marian-0.1.9 lib/codebreaker_marian/entities/data_storage.rb
codebreaker_marian-0.1.8 lib/codebreaker_marian/entities/data_storage.rb
codebreaker_marian-0.1.7 lib/codebreaker_marian/entities/data_storage.rb
codebreaker_marian-0.1.6 lib/codebreaker_marian/entities/data_storage.rb
codebreaker_marian-0.1.5 lib/codebreaker/entities/data_storage.rb