initial rebuild from v1
This commit is contained in:
3
app/models/application_record.rb
Normal file
3
app/models/application_record.rb
Normal file
@@ -0,0 +1,3 @@
|
||||
class ApplicationRecord < ActiveRecord::Base
|
||||
self.abstract_class = true
|
||||
end
|
||||
0
app/models/concerns/.keep
Normal file
0
app/models/concerns/.keep
Normal file
36
app/models/user.rb
Normal file
36
app/models/user.rb
Normal 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
|
||||
14
app/models/wow_character.rb
Normal file
14
app/models/wow_character.rb
Normal 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
|
||||
3
app/models/wow_character_medium.rb
Normal file
3
app/models/wow_character_medium.rb
Normal file
@@ -0,0 +1,3 @@
|
||||
class WowCharacterMedium < ApplicationRecord
|
||||
belongs_to :wow_character
|
||||
end
|
||||
9
app/models/wow_character_title.rb
Normal file
9
app/models/wow_character_title.rb
Normal 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
9
app/models/wow_class.rb
Normal 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
9
app/models/wow_race.rb
Normal 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
10
app/models/wow_realm.rb
Normal 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
|
||||
Reference in New Issue
Block a user