5 # This manages those players who have their player_id.
6 # Since mk_rate mainly updates the yaml file, basically,
7 # this only reads data. But this writes some properties.
8 # TODO Such data should be facoted out to another file
11 def initialize(filename)
12 @db = YAML::Store.new(filename)
13 @db.transaction do |pstore|
14 @db['players'] ||= Hash.new
19 # trancaction=true means read only
21 def each_group(transaction=false)
22 @db.transaction(transaction) do
23 groups = @db["players"] || Hash.new
24 groups.each do |group, players|
30 def load_player(player)
31 return unless player.player_id
34 each_group(true) do |group, players|
35 hash = players[player.player_id]
41 player.name = hash['name']
42 player.rate = hash['rate'] || 0
43 player.modified_at = hash['last_modified']
44 player.rating_group = hash['rating_group']
45 player.win = hash['win'] || 0
46 player.loss = hash['loss'] || 0
47 player.last_game_win = hash['last_game_win'] || false
51 return unless player.player_id
53 each_group do |group, players|
54 hash = players[player.player_id]
56 # write only this property.
57 # the others are updated by ./mk_rate
58 hash['last_game_win'] = player.last_game_win
66 each_group(true) do |group, players_hash|
67 players << players_hash.keys
69 return players.flatten.collect do |player_id|
71 p.player_id = player_id
76 end # class Persistent
79 end # module ShogiServer