Class: Account
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Account
- Defined in:
- lib/twitter/cli/models/account.rb
Class Method Summary collapse
- .active ⇒ Object
- .add(hash) ⇒ Object
- .new_active_needed? ⇒ Boolean
- .set_current(account_or_id) ⇒ Object
Instance Method Summary collapse
- #to_s ⇒ Object (also: #to_str)
Class Method Details
.active ⇒ Object
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) account = find_or_initialize_by_username(username) account.attributes = hash account.save set_current(account) if new_active_needed? end |
.new_active_needed? ⇒ 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(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 |
Instance Method Details
#to_s ⇒ Object Also known as: to_str
29 30 31 |
# File 'lib/twitter/cli/models/account.rb', line 29 def to_s "#{current? ? '*' : ' '} #{username}" end |