Sha256: e698fb8f671b2af5c78d5a29641c712df692c9daefd78947a25aa71fa9528a26

Contents?: true

Size: 716 Bytes

Versions: 3

Compression:

Stored size: 716 Bytes

Contents

# frozen_string_literal: true

module Codebreakergem
  class FileWorker
    PERMITTED_CLASSES = [Statistic, Difficulty, Easy, Medium, Hell].freeze

    class << self
      def read_from_file(filename)
        return nil unless File.file?(Game::FILE)

        YAML.safe_load(File.read(filename), PERMITTED_CLASSES, [], true)
      end

      def add_to_file(filename, data)
        data_in_file = Array(YAML.safe_load(File.read(filename), PERMITTED_CLASSES, [], true))
        data_in_file << data
        write_to_file(filename, data_in_file)
      end

      def write_to_file(filename, data)
        File.open(filename, 'w') { |file| file.write(data.to_yaml) }
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
codebreakergem-0.1.12 lib/classes/file_worker.rb
codebreakergem-0.1.11 lib/classes/file_worker.rb
codebreakergem-0.1.10 lib/classes/file_worker.rb