blob: a513ee16a5540b8a9a0acdddc39ffeea4aaa69bd (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# This file should contain all the record creation needed to seed the database with its default values.
# The data can then be loaded with the bin/rails db:seed command (or created alongside the database with db:setup).
#
# Examples:
#
# movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }])
# Character.create(name: 'Luke', movie: movies.first)
def load_data_file(path)
YAML.load(File.read(path)).deep_transform_keys(&:to_sym)
end
load_data_file("data/chat_rooms.yml").map do |gid, hash|
chat_room = ChatRoom.find_or_create_by(gid: gid)
chat_room.update(hash)
end
load_data_file("data/titles.yml").map do |gid, hash|
title = Title.find_or_create_by(gid: gid)
title.update(hash)
end
load_data_file("data/skills.yml").map do |gid, hash|
skill = Skill.find_or_create_by(gid: gid)
skill.update(hash)
end
Dir["data/items/*"].each do |file_name|
load_data_file(file_name).map do |gid, hash|
item = Item.find_or_create_by(gid: gid)
item.update(hash)
end
end
load_data_file("data/locations.yml").map do |gid, hash|
location = Location.find_or_create_by(gid: gid)
location.update(hash)
end
Dir["data/activities/*"].each do |file_name|
load_data_file(file_name).map do |gid, hash|
activity = Activity.find_or_create_by(gid: gid)
activity.assign_attributes(hash.except(:location))
activity.location = Location.find_by_gid(hash[:location])
activity.save
end
end
load_data_file("data/hearth_amenities.yml").map do |gid, hash|
hearth_amenity = HearthAmenity.find_or_create_by(gid: gid)
hearth_amenity.update(hash)
end
load_data_file("data/monsters.yml").map do |gid, hash|
monster = Monster.find_or_create_by(gid: gid)
monster.update(hash)
end
load_data_file("data/conditions.yml").map do |gid, hash|
condition = Condition.find_or_create_by(gid: gid)
condition.update(hash)
end
|