initial rebuild from v1

This commit is contained in:
2021-04-22 22:31:23 +02:00
commit cc8cf4954d
152 changed files with 11559 additions and 0 deletions

View File

@@ -0,0 +1,3 @@
class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true
end

View File

36
app/models/user.rb Normal file
View File

@@ -0,0 +1,36 @@
# frozen_string_literal: true
# Model: User
#
# Description: Define an application user. the only authentication mecanism
# is omniauthable with the BattleNet API
class User < ApplicationRecord
devise :rememberable, :omniauthable, omniauth_providers: [:bnet]
has_many :wow_characters, dependent: :destroy
validates :battletag, presence: true, uniqueness: true
def self.from_omniauth(auth)
user = User.where(provider: auth.provider, uid: auth.uid).first_or_initialize
user.provider = auth.provider
user.uid = auth.uid
user.battletag = auth.info.battletag
user.token_expires = auth.credentials.expires
user.token_expire_at = Time.at(auth.credentials.expires_at).utc
user.token = auth.credentials.token
user.save
user
end
def self.new_with_session(params, session)
super.tap do |user|
if (data = session['devise.bnet_data']) && session['devise.bnet_data']['extra']['raw_info']
user.email = data['email'] if user.email.blank?
end
end
end
end

View File

@@ -0,0 +1,14 @@
class WowCharacter < ApplicationRecord
extend Mobility
translates :translated_faction, :translated_gender
belongs_to :user
belongs_to :wow_realm
belongs_to :wow_class
belongs_to :wow_race
belongs_to :wow_character_title, optional: true
has_one :wow_character_medium, dependent: :nullify
validates :name, presence: true
validates :character_id, presence: true, uniqueness: true
end

View File

@@ -0,0 +1,3 @@
class WowCharacterMedium < ApplicationRecord
belongs_to :wow_character
end

View File

@@ -0,0 +1,9 @@
class WowCharacterTitle < ApplicationRecord
extend Mobility
translates :name, :male_name, :female_name
has_many :wow_characters, dependent: :nullify
validates :name, presence: true
validates :title_id, presence: true, uniqueness: true
end

9
app/models/wow_class.rb Normal file
View File

@@ -0,0 +1,9 @@
class WowClass < ApplicationRecord
extend Mobility
translates :name, :power_type, :male_name, :female_name
has_many :wow_characters, dependent: :nullify
validates :name, presence: true
validates :class_id, presence: true, uniqueness: true
end

9
app/models/wow_race.rb Normal file
View File

@@ -0,0 +1,9 @@
class WowRace < ApplicationRecord
extend Mobility
translates :name, :translated_faction, :male_name, :female_name
has_many :wow_characters, dependent: :nullify
validates :name, presence: true
validates :race_id, presence: true, uniqueness: true
end

10
app/models/wow_realm.rb Normal file
View File

@@ -0,0 +1,10 @@
class WowRealm < ApplicationRecord
extend Mobility
translates :name, :category, :realm_type
has_many :wow_characters, dependent: :nullify
validates :name, presence: true
validates :slug, presence: true
validates :realm_id, presence: true, uniqueness: true
end