aboutsummaryrefslogtreecommitdiffstats
path: root/app/models/account.rb
diff options
context:
space:
mode:
authorRhenium <rhenium@rhe.jp>2014-01-20 13:02:15 +0900
committerRhenium <rhenium@rhe.jp>2014-01-20 13:02:15 +0900
commitd282b7ef38f3cf42e8d9e4fd104228d0bf95f856 (patch)
treec182289010ed08e16fe8ebdeb25d219999ec2dea /app/models/account.rb
parent2ad52ebb033394cb721f55a90af977adfb596a16 (diff)
downloadaclog-d282b7ef38f3cf42e8d9e4fd104228d0bf95f856.tar.gz
update models
Diffstat (limited to 'app/models/account.rb')
-rw-r--r--app/models/account.rb39
1 files changed, 15 insertions, 24 deletions
diff --git a/app/models/account.rb b/app/models/account.rb
index 66c1523..91fd337 100644
--- a/app/models/account.rb
+++ b/app/models/account.rb
@@ -4,11 +4,14 @@ class Account < ActiveRecord::Base
ACTIVE = 0; INACTIVE = 1
belongs_to :user
-
scope :active, -> { where(status: Account::ACTIVE) }
+ alias notification? notification
+ alias private? private
+ def active?; status == Account::ACTIVE end
+
def self.create_or_update(hash)
- account = self.where(user_id: hash[:user_id]).first_or_initialize
+ 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 = Account::ACTIVE
@@ -20,17 +23,6 @@ class Account < ActiveRecord::Base
self.active.where("id % ? = ?", Settings.collector.count, collector_id)
end
- def notification?; self.notification end
- def private?; self.private end
- def active?; self.status == Account::ACTIVE end
-
- def update_settings!(params)
- self.notification = !!params[:notification]
- self.private = !!params[:private]
- self.save! if self.changed?
- self
- end
-
def deactivate!
self.status = Account::INACTIVE
self.save! if self.changed?
@@ -43,7 +35,7 @@ class Account < ActiveRecord::Base
client = MessagePack::RPC::Client.new(transport, Rails.root.join("tmp", "sockets", "receiver.sock").to_s)
client.call(:register, Marshal.dump(self))
rescue Errno::ECONNREFUSED, Errno::ENOENT
- Rails.logger.error "Account#update_connection: couldn't connect to the receiver"
+ logger.error("Account#update_connection: couldn't connect to the receiver")
end
def client
@@ -58,22 +50,21 @@ class Account < ActiveRecord::Base
Tweet.from_twitter_object(obj)
end
- def following?(target_user_id)
- api_friendship?(user_id, target_user_id)
+ def following?(target_id)
+ api_friendship?(self.user_id, target_id)
end
- def followed_by?(source_user_id)
- api_friendship?(source_user_id, user_id)
+ def followed_by?(source_id)
+ api_friendship?(source_id, self.user_id)
end
private
- def api_friendship?(source_user_id, target_user_id)
- return nil unless source_user_id.is_a?(Integer)
- return nil unless target_user_id.is_a?(Integer)
+ def api_friendship?(source_id, target_id)
+ return nil unless source_id.is_a?(Integer)
+ return nil unless target_id.is_a?(Integer)
- Rails.cache.fetch("friendship/#{source_user_id}-#{target_user_id}", expires_in: 3.days) do
- self.client.friendship?(source_user_id, target_user_id) rescue nil
+ Rails.cache.fetch("friendship/#{source_id}-#{target_id}", expires_in: 3.days) do
+ client.friendship?(source_id, target_id) rescue nil
end
end
end
-