discourse/lib/avatar_lookup.rb

22 lines
486 B
Ruby
Raw Normal View History

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