Class: AlexCodebreaker::GameManager

Inherits:
Object
  • Object
show all
Defined in:
lib/alex_codebreaker/game_manager.rb

Constant Summary collapse

FILENAME_EXTENSION =
'.yml'.freeze

Instance Method Summary collapse

Constructor Details

#initialize(game_id) ⇒ GameManager

Returns a new instance of GameManager.



5
6
7
# File 'lib/alex_codebreaker/game_manager.rb', line 5

def initialize(game_id)
  @game_id = game_id
end

Instance Method Details

#loadObject



16
17
18
19
20
# 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) ⇒ Object



9
10
11
12
13
14
# 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