Sha256: d298ee39a5d1d9d98fe6a3c72de93e2d8dfa36325c4480954510a132a77b1733

Contents?: true

Size: 662 Bytes

Versions: 1

Compression:

Stored size: 662 Bytes

Contents

module AlexCodebreaker
  class GameManager
    FILENAME_EXTENSION = '.yml'.freeze

    def initialize(game_id)
      @game_id = game_id
    end

    def save(game)
      unless File.directory?(AlexCodebreaker.configuration.games_folder_path)
        FileUtils.mkdir_p(AlexCodebreaker.configuration.games_folder_path)
      end
      File.open(game_file_path, 'w') { |file| file.write(game.to_yaml) }
    end

    def load
      return unless File.exist?(game_file_path)

      YAML.load_file(game_file_path)
    end

    private

    def game_file_path
      "#{AlexCodebreaker.configuration.games_folder_path}#{@game_id}#{FILENAME_EXTENSION}"
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
alex_codebreaker-0.2.1 lib/alex_codebreaker/game_manager.rb