2013-02-05 14:16:51 -05:00
|
|
|
class AvatarLookup
|
|
|
|
|
2013-05-25 02:50:39 -04:00
|
|
|
def initialize(user_ids=[])
|
2013-07-12 17:07:54 -04:00
|
|
|
@user_ids = user_ids.tap(&:compact!).tap(&:uniq!)
|
2013-02-05 14:16:51 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
# Lookup a user by id
|
|
|
|
def [](user_id)
|
2013-07-12 17:07:54 -04:00
|
|
|
users[user_id]
|
2013-02-05 14:16:51 -05:00
|
|
|
end
|
|
|
|
|
2013-05-25 02:50:39 -04:00
|
|
|
private
|
2013-02-05 14:16:51 -05:00
|
|
|
|
2013-07-12 17:07:54 -04:00
|
|
|
def users
|
|
|
|
@users ||= User.where(:id => @user_ids).select([:id, :email, :username]).inject({}) do |hash, user|
|
|
|
|
hash.merge({user.id => user})
|
|
|
|
end
|
2013-05-25 02:50:39 -04:00
|
|
|
end
|
2013-02-05 14:16:51 -05:00
|
|
|
end
|