Class: Account

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/twitter/cli/models/account.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.activeObject



14
15
16
# File 'lib/twitter/cli/models/account.rb', line 14

def self.active
  current.first
end

.add(hash) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/twitter/cli/models/account.rb', line 6

def self.add(hash)
  username = hash.delete(:username)
   = find_or_initialize_by_username(username)
  .attributes = hash
  .save
  set_current() if new_active_needed?
end

.new_active_needed?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/twitter/cli/models/account.rb', line 25

def self.new_active_needed?
  self.current.count == 0 && self.count > 0
end

.set_current(account_or_id) ⇒ Object



18
19
20
21
22
23
# File 'lib/twitter/cli/models/account.rb', line 18

def self.set_current()
   = .is_a?(Account) ?  : find()
  .update_attribute :current, true
  Account.update_all "current = 0", "id != #{.id}"
  
end

Instance Method Details

#to_sObject Also known as: to_str



29
30
31
# File 'lib/twitter/cli/models/account.rb', line 29

def to_s
  "#{current? ? '*' : ' '} #{username}"
end