diff options
author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2017-10-03 15:11:00 -0400 |
---|---|---|
committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2017-10-03 15:11:00 -0400 |
commit | b618e52428bb659cb1fe3bdbe3d3763d48b4556c (patch) | |
tree | 58446ae6883c4257013bc93375cfd668720bce95 | |
parent | 34830f2e96e4213e8acb10ea457244c7523aeb5a (diff) | |
download | pokeviewer-b618e52428bb659cb1fe3bdbe3d3763d48b4556c.tar.gz pokeviewer-b618e52428bb659cb1fe3bdbe3d3763d48b4556c.tar.bz2 pokeviewer-b618e52428bb659cb1fe3bdbe3d3763d48b4556c.zip |
Made "met location" into an actual association
-rw-r--r-- | app/jobs/pokeviewer/extract_save_data_job.rb | 4 | ||||
-rw-r--r-- | app/models/pokeviewer/location.rb | 2 | ||||
-rw-r--r-- | app/models/pokeviewer/pokemon.rb | 12 | ||||
-rw-r--r-- | db/migrate/20171003154157_rename_pokemon_met_location.rb | 30 | ||||
-rw-r--r-- | test/dummy/db/schema.rb | 4 |
5 files changed, 40 insertions, 12 deletions
diff --git a/app/jobs/pokeviewer/extract_save_data_job.rb b/app/jobs/pokeviewer/extract_save_data_job.rb index 546e6d2..99d71f1 100644 --- a/app/jobs/pokeviewer/extract_save_data_job.rb +++ b/app/jobs/pokeviewer/extract_save_data_job.rb | |||
@@ -69,7 +69,7 @@ module Pokeviewer | |||
69 | 69 | ||
70 | if param["metLevel"] == 0 | 70 | if param["metLevel"] == 0 |
71 | r.met_type = :hatched | 71 | r.met_type = :hatched |
72 | r.met_location = param["metLocation"] | 72 | r.location_id = param["metLocation"] |
73 | elsif param["metLocation"] == 254 | 73 | elsif param["metLocation"] == 254 |
74 | r.met_type = :npc_trade | 74 | r.met_type = :npc_trade |
75 | elsif param["metLocation"] == 255 | 75 | elsif param["metLocation"] == 255 |
@@ -78,7 +78,7 @@ module Pokeviewer | |||
78 | else | 78 | else |
79 | r.met_type = :normal | 79 | r.met_type = :normal |
80 | r.met_level = param["metLevel"] | 80 | r.met_level = param["metLevel"] |
81 | r.met_location = param["metLocation"] | 81 | r.location_id = param["metLocation"] |
82 | end | 82 | end |
83 | 83 | ||
84 | r.shiny = param["shiny"] | 84 | r.shiny = param["shiny"] |
diff --git a/app/models/pokeviewer/location.rb b/app/models/pokeviewer/location.rb index e497cbc..db37df2 100644 --- a/app/models/pokeviewer/location.rb +++ b/app/models/pokeviewer/location.rb | |||
@@ -1,5 +1,7 @@ | |||
1 | module Pokeviewer | 1 | module Pokeviewer |
2 | class Location < ApplicationRecord | 2 | class Location < ApplicationRecord |
3 | has_many :pokemon, dependent: :nullify | ||
4 | |||
3 | validates :name, presence: true | 5 | validates :name, presence: true |
4 | end | 6 | end |
5 | end | 7 | end |
diff --git a/app/models/pokeviewer/pokemon.rb b/app/models/pokeviewer/pokemon.rb index 6c33406..9f0b4af 100644 --- a/app/models/pokeviewer/pokemon.rb +++ b/app/models/pokeviewer/pokemon.rb | |||
@@ -24,6 +24,10 @@ module Pokeviewer | |||
24 | validates :met_type, presence: true | 24 | validates :met_type, presence: true |
25 | enumerize :met_type, in: [:normal, :hatched, :npc_trade, :fateful_encounter] | 25 | enumerize :met_type, in: [:normal, :hatched, :npc_trade, :fateful_encounter] |
26 | 26 | ||
27 | belongs_to :location, optional: true | ||
28 | validates :location, presence: true, | ||
29 | if: Proc.new { |c| c.met_type == :normal or c.met_type == :hatched} | ||
30 | |||
27 | validates :gender, presence: true | 31 | validates :gender, presence: true |
28 | enumerize :gender, in: [:genderless, :female, :male] | 32 | enumerize :gender, in: [:genderless, :female, :male] |
29 | 33 | ||
@@ -105,14 +109,6 @@ module Pokeviewer | |||
105 | (trainer.nil?) or (ot_name != trainer.name) or (ot_number != trainer.number) | 109 | (trainer.nil?) or (ot_name != trainer.name) or (ot_number != trainer.number) |
106 | end | 110 | end |
107 | 111 | ||
108 | def location | ||
109 | if (met_type == :normal) or (met_type == :hatched) | ||
110 | Location.find_by_id(met_location) | ||
111 | else | ||
112 | nil | ||
113 | end | ||
114 | end | ||
115 | |||
116 | def display_ot_number | 112 | def display_ot_number |
117 | ot_number.to_s.rjust(5, '0') | 113 | ot_number.to_s.rjust(5, '0') |
118 | end | 114 | end |
diff --git a/db/migrate/20171003154157_rename_pokemon_met_location.rb b/db/migrate/20171003154157_rename_pokemon_met_location.rb new file mode 100644 index 0000000..4ccba57 --- /dev/null +++ b/db/migrate/20171003154157_rename_pokemon_met_location.rb | |||
@@ -0,0 +1,30 @@ | |||
1 | class RenamePokemonMetLocation < ActiveRecord::Migration[5.1] | ||
2 | def up | ||
3 | add_column :pokeviewer_pokemon, :location_id, :integer, null: true | ||
4 | |||
5 | add_foreign_key :pokeviewer_pokemon, :pokeviewer_locations, | ||
6 | column: :location_id | ||
7 | |||
8 | Pokeviewer::Pokemon.all.each do |p| | ||
9 | unless p.met_location.nil? | ||
10 | p.location_id = p.met_location.to_i | ||
11 | p.save! | ||
12 | end | ||
13 | end | ||
14 | |||
15 | remove_column :pokeviewer_pokemon, :met_location | ||
16 | end | ||
17 | |||
18 | def down | ||
19 | add_column :pokeviewer_pokemon, :met_location, :string | ||
20 | |||
21 | Pokeviewer::Pokemon.all.each do |p| | ||
22 | unless p.location_id.nil? | ||
23 | p.met_location = p.location_id.to_s | ||
24 | p.save! | ||
25 | end | ||
26 | end | ||
27 | |||
28 | remove_column :pokeviewer_pokemon, :location_id | ||
29 | end | ||
30 | end | ||
diff --git a/test/dummy/db/schema.rb b/test/dummy/db/schema.rb index 84e15a3..87db1f8 100644 --- a/test/dummy/db/schema.rb +++ b/test/dummy/db/schema.rb | |||
@@ -10,7 +10,7 @@ | |||
10 | # | 10 | # |
11 | # It's strongly recommended that you check this file into your version control system. | 11 | # It's strongly recommended that you check this file into your version control system. |
12 | 12 | ||
13 | ActiveRecord::Schema.define(version: 20170930213633) do | 13 | ActiveRecord::Schema.define(version: 20171003154157) do |
14 | 14 | ||
15 | create_table "pokeviewer_boxes", force: :cascade do |t| | 15 | create_table "pokeviewer_boxes", force: :cascade do |t| |
16 | t.integer "trainer_id", null: false | 16 | t.integer "trainer_id", null: false |
@@ -66,7 +66,6 @@ ActiveRecord::Schema.define(version: 20170930213633) do | |||
66 | t.string "ot_name", null: false | 66 | t.string "ot_name", null: false |
67 | t.integer "ot_number", null: false | 67 | t.integer "ot_number", null: false |
68 | t.string "met_type", null: false | 68 | t.string "met_type", null: false |
69 | t.string "met_location" | ||
70 | t.integer "met_level" | 69 | t.integer "met_level" |
71 | t.boolean "shiny", default: false, null: false | 70 | t.boolean "shiny", default: false, null: false |
72 | t.string "nature", null: false | 71 | t.string "nature", null: false |
@@ -78,6 +77,7 @@ ActiveRecord::Schema.define(version: 20170930213633) do | |||
78 | t.string "ot_gender", default: "", null: false | 77 | t.string "ot_gender", default: "", null: false |
79 | t.integer "box" | 78 | t.integer "box" |
80 | t.integer "slot" | 79 | t.integer "slot" |
80 | t.integer "location_id" | ||
81 | t.index ["key"], name: "index_pokeviewer_pokemon_on_key", unique: true | 81 | t.index ["key"], name: "index_pokeviewer_pokemon_on_key", unique: true |
82 | t.index ["species_id"], name: "index_pokeviewer_pokemon_on_species_id" | 82 | t.index ["species_id"], name: "index_pokeviewer_pokemon_on_species_id" |
83 | t.index ["trainer_id"], name: "index_pokeviewer_pokemon_on_trainer_id" | 83 | t.index ["trainer_id"], name: "index_pokeviewer_pokemon_on_trainer_id" |