diff options
author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2017-09-16 22:40:16 -0400 |
---|---|---|
committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2017-09-16 22:40:16 -0400 |
commit | 1d621019d7bf74b65898e009aef31766c7e7572b (patch) | |
tree | bc48ac9c980ff3cc5d087beece6ed0fe24d441da /app/models | |
parent | 5e62e771bf14f58dd1622d2e3631309caa201349 (diff) | |
download | pokeviewer-1d621019d7bf74b65898e009aef31766c7e7572b.tar.gz pokeviewer-1d621019d7bf74b65898e009aef31766c7e7572b.tar.bz2 pokeviewer-1d621019d7bf74b65898e009aef31766c7e7572b.zip |
Created a bunch of models
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/pokeviewer/move.rb | 10 | ||||
-rw-r--r-- | app/models/pokeviewer/pokemon.rb | 50 | ||||
-rw-r--r-- | app/models/pokeviewer/revision.rb | 72 | ||||
-rw-r--r-- | app/models/pokeviewer/revision_move.rb | 19 | ||||
-rw-r--r-- | app/models/pokeviewer/species.rb | 7 | ||||
-rw-r--r-- | app/models/pokeviewer/trainer.rb | 17 |
6 files changed, 175 insertions, 0 deletions
diff --git a/app/models/pokeviewer/move.rb b/app/models/pokeviewer/move.rb new file mode 100644 index 0000000..337ac11 --- /dev/null +++ b/app/models/pokeviewer/move.rb | |||
@@ -0,0 +1,10 @@ | |||
1 | module Pokeviewer | ||
2 | class Move < ApplicationRecord | ||
3 | has_many :revision_moves | ||
4 | has_many :revisions, through: :revision_moves | ||
5 | |||
6 | validates :name, presence: true, uniqueness: true | ||
7 | validates :pp, presence: true, | ||
8 | numericality: { greater_than_or_equal_to: 1, only_integer: true } | ||
9 | end | ||
10 | end | ||
diff --git a/app/models/pokeviewer/pokemon.rb b/app/models/pokeviewer/pokemon.rb new file mode 100644 index 0000000..114e9dd --- /dev/null +++ b/app/models/pokeviewer/pokemon.rb | |||
@@ -0,0 +1,50 @@ | |||
1 | module Pokeviewer | ||
2 | class Pokemon < ApplicationRecord | ||
3 | extend Enumerize | ||
4 | |||
5 | belongs_to :species | ||
6 | belongs_to :trainer, optional: true | ||
7 | has_many :revisions, dependent: :destroy | ||
8 | |||
9 | validate :uuid_is_constant, on: :update | ||
10 | before_create :set_uuid | ||
11 | |||
12 | validates :ot_name, presence: true | ||
13 | |||
14 | validates :ot_number, presence: true, | ||
15 | numericality: { greater_than_or_equal_to: 0, only_integer: true } | ||
16 | |||
17 | validates :met_level, presence: true, | ||
18 | numericality: { greater_than_or_equal_to: 1, only_integer: true } | ||
19 | |||
20 | validates :met_type, presence: true | ||
21 | enumerize :met_type, in: [:normal, :hatched, :npc_trade, :fateful_encounter] | ||
22 | |||
23 | validates :gender, presence: true | ||
24 | enumerize :gender, in: [:genderless, :female, :male] | ||
25 | |||
26 | validates :nature, presence: true | ||
27 | enumerize :nature, in: [:hardy, :lonely, :brave, :adamant, :naughty, :bold, | ||
28 | :docile, :relaxed, :impish, :lax, :timid, :hasty, :serious, :jolly, | ||
29 | :naive, :modest, :mild, :quiet, :bashful, :rash, :calm, :gentle, :sassy, | ||
30 | :careful, :quirky] | ||
31 | |||
32 | enumerize :unown_letter, in: [:a, :b, :c, :d, :e, :f, :g, :h, :i, :j, :k, | ||
33 | :l, :m, :n, :o, :p, :q, :r, :s, :t, :u, :v, :w, :x, :y, :z, | ||
34 | :question_mark, :exclamation_mark] | ||
35 | |||
36 | def to_param | ||
37 | uuid | ||
38 | end | ||
39 | |||
40 | private | ||
41 | |||
42 | def set_uuid | ||
43 | self.uuid = SecureRandom.uuid | ||
44 | end | ||
45 | |||
46 | def uuid_is_constant | ||
47 | errors.add(:uuid, "can't be changed") if self.uuid_changed? | ||
48 | end | ||
49 | end | ||
50 | end | ||
diff --git a/app/models/pokeviewer/revision.rb b/app/models/pokeviewer/revision.rb new file mode 100644 index 0000000..a8f8ab2 --- /dev/null +++ b/app/models/pokeviewer/revision.rb | |||
@@ -0,0 +1,72 @@ | |||
1 | module Pokeviewer | ||
2 | class Revision < ApplicationRecord | ||
3 | belongs_to :pokemon | ||
4 | acts_as_sequenced scope: :pokemon_id | ||
5 | |||
6 | has_many :revision_moves, -> { order "number ASC" } | ||
7 | has_many :moves, through: :revision_moves | ||
8 | |||
9 | validates :moves, presence: true | ||
10 | validates :nickname, presence: true | ||
11 | |||
12 | validates :experience, presence: true, | ||
13 | numericality: { greater_than_or_equal_to: 1, only_integer: true } | ||
14 | |||
15 | validates :level, presence: true, | ||
16 | numericality: { greater_than_or_equal_to: 1, only_integer: true } | ||
17 | |||
18 | validates :hp, presence: true, | ||
19 | numericality: { greater_than_or_equal_to: 1, only_integer: true } | ||
20 | |||
21 | validates :attack, presence: true, | ||
22 | numericality: { greater_than_or_equal_to: 1, only_integer: true } | ||
23 | |||
24 | validates :defense, presence: true, | ||
25 | numericality: { greater_than_or_equal_to: 1, only_integer: true } | ||
26 | |||
27 | validates :special_attack, presence: true, | ||
28 | numericality: { greater_than_or_equal_to: 1, only_integer: true } | ||
29 | |||
30 | validates :special_defense, presence: true, | ||
31 | numericality: { greater_than_or_equal_to: 1, only_integer: true } | ||
32 | |||
33 | validates :speed, presence: true, | ||
34 | numericality: { greater_than_or_equal_to: 1, only_integer: true } | ||
35 | |||
36 | validates :coolness, presence: true, | ||
37 | numericality: { | ||
38 | greater_than_or_equal_to: 0, | ||
39 | less_than_or_equal_to: 10, | ||
40 | only_integer: true } | ||
41 | |||
42 | validates :beauty, presence: true, | ||
43 | numericality: { | ||
44 | greater_than_or_equal_to: 0, | ||
45 | less_than_or_equal_to: 10, | ||
46 | only_integer: true } | ||
47 | |||
48 | validates :cuteness, presence: true, | ||
49 | numericality: { | ||
50 | greater_than_or_equal_to: 0, | ||
51 | less_than_or_equal_to: 10, | ||
52 | only_integer: true } | ||
53 | |||
54 | validates :smartness, presence: true, | ||
55 | numericality: { | ||
56 | greater_than_or_equal_to: 0, | ||
57 | less_than_or_equal_to: 10, | ||
58 | only_integer: true } | ||
59 | |||
60 | validates :toughness, presence: true, | ||
61 | numericality: { | ||
62 | greater_than_or_equal_to: 0, | ||
63 | less_than_or_equal_to: 10, | ||
64 | only_integer: true } | ||
65 | |||
66 | validates :sheen, presence: true, | ||
67 | numericality: { | ||
68 | greater_than_or_equal_to: 0, | ||
69 | less_than_or_equal_to: 10, | ||
70 | only_integer: true } | ||
71 | end | ||
72 | end | ||
diff --git a/app/models/pokeviewer/revision_move.rb b/app/models/pokeviewer/revision_move.rb new file mode 100644 index 0000000..74b9e9e --- /dev/null +++ b/app/models/pokeviewer/revision_move.rb | |||
@@ -0,0 +1,19 @@ | |||
1 | module Pokeviewer | ||
2 | class RevisionMove < ApplicationRecord | ||
3 | belongs_to :revision | ||
4 | belongs_to :move | ||
5 | |||
6 | validates :number, presence: true, | ||
7 | numericality: { | ||
8 | greater_than_or_equal_to: 1, | ||
9 | less_than_or_equal_to: 4, | ||
10 | only_integer: true }, | ||
11 | uniqueness: { scope: :revision_id } | ||
12 | |||
13 | validates :pp_bonuses, presence: true, | ||
14 | numericality: { | ||
15 | greater_than_or_equal_to: 0, | ||
16 | less_than_or_equal_to: 3, | ||
17 | only_integer: true} | ||
18 | end | ||
19 | end | ||
diff --git a/app/models/pokeviewer/species.rb b/app/models/pokeviewer/species.rb new file mode 100644 index 0000000..c69fd21 --- /dev/null +++ b/app/models/pokeviewer/species.rb | |||
@@ -0,0 +1,7 @@ | |||
1 | module Pokeviewer | ||
2 | class Species < ApplicationRecord | ||
3 | has_many :pokemon, dependent: :restrict_with_exception | ||
4 | |||
5 | validates :name, presence: true, uniqueness: true | ||
6 | end | ||
7 | end | ||
diff --git a/app/models/pokeviewer/trainer.rb b/app/models/pokeviewer/trainer.rb new file mode 100644 index 0000000..1cef881 --- /dev/null +++ b/app/models/pokeviewer/trainer.rb | |||
@@ -0,0 +1,17 @@ | |||
1 | module Pokeviewer | ||
2 | class Trainer < ApplicationRecord | ||
3 | extend Enumerize | ||
4 | |||
5 | has_many :pokemon, dependent: :nullify | ||
6 | |||
7 | validates :number, presence: true, | ||
8 | numericality: { greater_than_or_equal_to: 0, only_integer: true } | ||
9 | |||
10 | validates :name, presence: true, uniqueness: { | ||
11 | scope: :number, | ||
12 | message: "and number should be pairwise unique" } | ||
13 | |||
14 | validates :game, presence: true | ||
15 | enumerize :game, in: [:ruby, :sapphire, :firered, :leafgreen, :emerald] | ||
16 | end | ||
17 | end | ||