aboutsummaryrefslogtreecommitdiffstats
path: root/app/models/account.rb
diff options
context:
space:
mode:
authorrhenium <rhenium@rhe.jp>2014-07-18 06:06:10 +0900
committerrhenium <rhenium@rhe.jp>2014-07-18 06:06:10 +0900
commit2e0b9ea57de549ca452fb557d3dc684a03d70aa4 (patch)
treeb940b5418fa96d005f414814390d8abfa05d221d /app/models/account.rb
parent057b07f072b02dc22dae4b82aed5c4e9483f5b10 (diff)
downloadaclog-2e0b9ea57de549ca452fb557d3dc684a03d70aa4.tar.gz
refactor models
Diffstat (limited to 'app/models/account.rb')
-rw-r--r--app/models/account.rb41
1 files changed, 17 insertions, 24 deletions
diff --git a/app/models/account.rb b/app/models/account.rb
index bb6b9bd..d3c23ab 100644
--- a/app/models/account.rb
+++ b/app/models/account.rb
@@ -7,33 +7,26 @@ class Account < ActiveRecord::Base
scope :for_node, ->(block_number) { active.where("id % ? = ?", Settings.collector.nodes_count, block_number) }
def notification_enabled?; notification_enabled end
+ def deactivate!; self.inactive! end
+
+ class << self
+ def register(hash)
+ account = where(user_id: hash[:user_id]).first_or_initialize
+ account.oauth_token = hash[:oauth_token]
+ account.oauth_token_secret = hash[:oauth_token_secret]
+ account.status = :active
+ account.save! if account.changed?
+ end
- def self.create_or_update(hash)
- account = where(user_id: hash[:user_id]).first_or_initialize
- account.oauth_token = hash[:oauth_token]
- account.oauth_token_secret = hash[:oauth_token_secret]
- account.status = :active
- account.save if account.changed?
- account
- end
-
- def self.random
- self.active.order("RAND()").first
- end
-
- def deactivate!
- self.inactive!
-
- WorkerManager.update_account(self)
- rescue Aclog::Exceptions::WorkerConnectionError
+ def random
+ active.order("RAND()").first
+ end
end
def verify_token!
- begin
- client.user
- rescue
- self.revoked!
- end
+ client.user
+ rescue
+ self.revoked!
end
def client
@@ -44,7 +37,7 @@ class Account < ActiveRecord::Base
end
def following?(target_id)
- target_id = target_id.id if target_id.is_a? User
+ target_id = target_id.id if target_id.is_a?(User)
friends.member? target_id
end