about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--app/jobs/pokeviewer/extract_save_data_job.rb4
-rw-r--r--app/models/pokeviewer/location.rb2
-rw-r--r--app/models/pokeviewer/pokemon.rb12
-rw-r--r--db/migrate/20171003154157_rename_pokemon_met_location.rb30
-rw-r--r--test/dummy/db/schema.rb4
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 @@
1module Pokeviewer 1module 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
5end 7end
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 @@
1class 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
30end
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
13ActiveRecord::Schema.define(version: 20170930213633) do 13ActiveRecord::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"