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