aboutsummaryrefslogtreecommitdiffstats
path: root/app/models/user.rb
blob: b93eac90c47ca0cb6f6869bf85e6e45aecc989af (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
class User < ActiveRecord::Base
  def initialize(attrs = {})
    if attrs.is_a?(Fixnum) || attrs.is_a?(Bignum)
      u = attrs
      attrs = {:id => u}
    end
    attrs[:profile_image_url] ||= ActionController::Base.helpers.asset_path("missing_profile_image.png")
    attrs[:name] ||= "Missing name: #{u}"
    super(attrs)
  end

  has_many :tweets, :dependent => :delete_all
  has_many :favorites, :dependent => :delete_all
  has_many :retweets, :dependent => :delete_all

  def self.cached(uid)
    Rails.cache.fetch("user/#{uid}", :expires_in => 1.hour) do
      where(:id => uid).first
    end
  end

  def registered?
    Account.exists?(:user_id => id)
  end
end