ensl.org/app/models/profile.rb
Ari Timonen e59e8ac8e7 Lots of rails 4 updates
- Add .params to models and update controllers
- Add afk time to gather
- Reannotate models
- Fix rspec problem by using latest rspec plugins from github
2020-03-18 05:38:17 +02:00

110 lines
3.8 KiB
Ruby

# == Schema Information
#
# Table name: profiles
#
# id :integer not null, primary key
# achievements :text(65535)
# achievements_parsed :string(400)
# avatar :string(255)
# beverage :string(255)
# book :string(255)
# case :string(255)
# clan_search :string(255)
# cpu :string(255)
# food :string(255)
# gpu :string(255)
# hdd :string(255)
# head_phones :string(255)
# hobby :string(255)
# icq :string(255)
# irc :string(255)
# keyboard :string(255)
# layout :string(255)
# monitor :string(255)
# monitor_hz :string(255)
# motherboard :string(255)
# mouse :string(255)
# mouse_pad :string(255)
# movie :string(255)
# msn :string(255)
# multiplayer :string(255)
# music :string(255)
# notify_any_match :boolean
# notify_articles :boolean
# notify_challenge :boolean default("1"), not null
# notify_gather :boolean
# notify_movies :boolean
# notify_news :boolean
# notify_own_match :boolean
# notify_pms :boolean default("1"), not null
# psu :string(255)
# ram :string(255)
# res :string(255)
# scripts :string(255)
# sensitivity :string(255)
# signature :string(255)
# signature_parsed :text(65535)
# singleplayer :string(255)
# soundcard :string(255)
# speakers :string(255)
# steam_profile :string(255)
# stream :string(255)
# town :string(255)
# tvseries :string(255)
# web :string(255)
# updated_at :datetime
# user_id :integer
#
# Indexes
#
# index_profiles_on_user_id (user_id)
#
class Profile < ActiveRecord::Base
include Extra
#attr_protected :user_id, :id, :updated_at, :created_at
belongs_to :user
validates_length_of :msn, :maximum => 50
validates_format_of :msn, :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i, :allow_blank => true
validates_format_of :icq, :with => /\A[0-9\-]{1,9}\z/, :allow_blank => true
validates_length_of :irc, :maximum => 20
validates_length_of :web, :maximum => 100
validates_length_of :town, :maximum => 20
validates_length_of [:singleplayer, :multiplayer, :food, :beverage, :hobby, :music, :book, :movie, :tvseries], :maximum => 120
validates_length_of [:res, :sensitivity, :monitor_hz], :maximum => 30
validates_length_of [:scripts, :cpu, :gpu, :ram, :psu, :motherboard, :soundcard, :hdd, :case, :monitor, :mouse, :mouse_pad, :keyboard, :head_phones, :speakers], :maximum => 100
validates_length_of :signature, :maximum => 255
validates_length_of :achievements, :maximum => 65000
validates_format_of :steam_profile, :with => /\A[A-Za-z0-9_\-\+]{1,40}\z/, :allow_blank => true
validates :stream, :length => {:maximum => 30}
before_validation :init_steam_profile
before_save :parse_text
mount_uploader :avatar, AvatarUploader
def init_steam_profile
if steam_profile
if (m = steam_profile.to_s.match(/http:\/\/steamcommunity\.com\/profiles\/([0-9]*)/))
self.steam_profile = m[1]
elsif (m = steam_profile.to_s.match(/http:\/\/steamcommunity\.com\/id\/([A-Za-z0-9_\-\+]*)/))
self.steam_profile = m[1]
end
end
end
def parse_text
self.achievements_parsed = bbcode_to_html(achievements) if self.achievements
self.signature_parsed = bbcode_to_html(signature) if self.signature
end
def self.params(params, cuser)
# FIXME: check this, add user_id
# TEST
params.require(:profile).except!(:id, :updated_at).permit!
end
end