fun key: String is abstract
# Saves `self` in db.
- fun save do game.db.collection(collection_name).save(to_json)
+ fun save do game.db.collection(collection_name).save(to_json_object)
# Json representation of `self`.
- fun to_json: JsonObject do
+ fun to_json_object: JsonObject do
var json = new JsonObject
json["_id"] = key
return json
redef var key = name is lazy
# Mongo server url where this game data are stored.
- var mongo_url = "mongodb://localhost:27017" is writable
+ var mongo_url = "mongodb://mongo:27017" is writable
# Mongo db client.
var client = new MongoClient(mongo_url) is lazy
redef var collection_name = "games"
# Init the Game and try to load saved data.
- init do
+ init from_mongo(api: GithubAPI, repo: Repo) do
+ init(api, repo)
var req = new JsonObject
req["name"] = repo.full_name
var res = db.collection("games").find(req)
# Used to load entities from saved data.
fun from_json(json: JsonObject) do end
- redef fun to_json do
+ redef fun to_json_object do
var json = super
json["name"] = name
return json
end
# Erase all saved data for this game.
- fun clear do db.collection(collection_name).remove(to_json)
+ fun clear do db.collection(collection_name).remove(to_json_object)
# Verbosity level used fo stdout.
#
#
# Used to load players from saved data.
init from_json(game: Game, json: JsonObject) do
- init(game, json["name"].to_s)
+ init(game, json["name"].as(String))
nitcoins = json["nitcoins"].as(Int)
end
- redef fun to_json do
+ redef fun to_json_object do
var json = super
json["game"] = game.key
json["name"] = name