class AlexCodebreaker::GameManager

Constants

FILENAME_EXTENSION

Public Class Methods

new(game_id) click to toggle source
# File lib/alex_codebreaker/game_manager.rb, line 5
def initialize(game_id)
  @game_id = game_id
end

Public Instance Methods

load() click to toggle source
# File lib/alex_codebreaker/game_manager.rb, line 16
def load
  return unless File.exist?(game_file_path)

  YAML.load_file(game_file_path)
end
save(game) click to toggle source
# File lib/alex_codebreaker/game_manager.rb, line 9
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

Private Instance Methods

game_file_path() click to toggle source
# File lib/alex_codebreaker/game_manager.rb, line 24
def game_file_path
  "#{AlexCodebreaker.configuration.games_folder_path}/#{@game_id}#{FILENAME_EXTENSION}"
end