Sha256: 0accb57610a5c9bf1632a165b83d1efe20f6a0967f89df03d89a9b4e213c2984

Contents?: true

Size: 605 Bytes

Versions: 9

Compression:

Stored size: 605 Bytes

Contents

module Codebreaker
  module Entities
    class Storage
      FILE_NAME = 'data.yml'.freeze

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

      def load
        YAML.load(File.open(FILE_NAME), [Menu]) if file_exists?
      end

      def save(object)
        File.open(FILE_NAME, 'w') { |file| file.write(YAML.dump(object)) }
      end

      def save_game_results(object)
        create unless file_exists?
        save(load.push(object))
      end

      private

      def file_exists?
        File.exist?(FILE_NAME)
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
codebreaker_artuomka-0.1.8 lib/codebreaker/entities/storage.rb
codebreaker_artuomka-0.1.7 lib/codebreaker/entities/storage.rb
codebreaker_artuomka-0.1.6 lib/codebreaker/entities/storage.rb
codebreaker_artuomka-0.1.5 lib/codebreaker/entities/storage.rb
codebreaker_artuomka-0.1.4 lib/codebreaker/entities/storage.rb
codebreaker_artuomka-0.1.3 lib/codebreaker/entities/storage.rb
codebreaker_artuomka-0.1.2 lib/codebreaker/entities/storage.rb
codebreaker_artuomka-0.1.1 lib/codebreaker/entities/storage.rb
codebreaker_artuomka-0.1.0 lib/codebreaker/entities/storage.rb