summaryrefslogtreecommitdiff
path: root/db/seeds.rb
blob: 2008d8954314f52c218155d6afa6a84d7bc8aa51 (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
# 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/skills.yml").map do |gid, hash|
  skill = Skill.find_or_create_by(gid: gid)
  skill.update(hash)
end

load_data_file("data/items.yml").map do |gid, hash|
  item = Item.find_or_create_by(gid: gid)
  item.name = hash[:name]
  item.description = hash[:description]
  item.equip_slot = hash[:equip_slot]&.to_sym
  item.usable = hash[:usable] || false
  item.whatnot = hash[:whatnot]
  item.save
end