Sha256: 069f1c22ca769ee99586fc66502177d0c734ba9f05deddd38302ba10885b129b

Contents?: true

Size: 816 Bytes

Versions: 36

Compression:

Stored size: 816 Bytes

Contents

class Account < ActiveRecord::Base
  named_scope :current, :conditions => {:current => true}
  
  has_many :tweets, :dependent => :destroy
  
  def self.add(hash)
    username = hash.delete(:username)
    account = find_or_initialize_by_username(username)
    account.attributes = hash
    account.save
    set_current(account) if new_active_needed?
  end
  
  def self.active
    current.first
  end
  
  def self.set_current(account_or_id)
    account = account_or_id.is_a?(Account) ? account_or_id : find(account_or_id)
    account.update_attribute :current, true
    Account.update_all "current = 0", "id != #{account.id}"
    account
  end
  
  def self.new_active_needed?
    self.current.count == 0 && self.count > 0
  end
  
  def to_s
    "#{current? ? '*' : ' '} #{username}"
  end
  alias to_str to_s
end

Version data entries

36 entries across 36 versions & 15 rubygems

Version Path
anthonycrumley-twitter-0.3.8 lib/twitter/cli/models/account.rb
baron-twitter-0.4.2 lib/twitter/cli/models/account.rb
billymeltdown-twitter-0.3.8.1 lib/twitter/cli/models/account.rb
billymeltdown-twitter-0.4.2 lib/twitter/cli/models/account.rb
billymeltdown-twitter-0.4.3 lib/twitter/cli/models/account.rb
drnic-twitter-0.4.4.1 lib/twitter/cli/models/account.rb
dschn-twitter-0.3.7.1 lib/twitter/cli/models/account.rb
dschn-twitter-0.3.7.2 lib/twitter/cli/models/account.rb
dschn-twitter-0.4.1.1 lib/twitter/cli/models/account.rb
dschn-twitter-0.4.1.2 lib/twitter/cli/models/account.rb
dschn-twitter-0.4.1.3 lib/twitter/cli/models/account.rb
dschn-twitter-0.4.1 lib/twitter/cli/models/account.rb
dustin-twitter-0.3.2.1 lib/twitter/cli/models/account.rb
dustin-twitter-0.3.2.2 lib/twitter/cli/models/account.rb
dustin-twitter-0.3.7 lib/twitter/cli/models/account.rb
gilesbowkett-gilesbowkett-twitter-0.4.4 lib/twitter/cli/models/account.rb
gilesbowkett-twitter-0.4.3 lib/twitter/cli/models/account.rb
gilesbowkett-twitter-0.4.5 lib/twitter/cli/models/account.rb
handcrafted-twitter-0.4.0 lib/twitter/cli/models/account.rb
handcrafted-twitter-0.4.2 lib/twitter/cli/models/account.rb