discourse/lib/avatar_lookup.rb
2013-07-12 23:10:21 +02:00

20 lines
360 B
Ruby

class AvatarLookup
def initialize(user_ids=[])
@user_ids = user_ids.tap(&:compact!).tap(&:uniq!)
end
# Lookup a user by id
def [](user_id)
users[user_id]
end
private
def users
@users ||= User.where(:id => @user_ids).select([:id, :email, :username]).inject({}) do |hash, user|
hash.merge({user.id => user})
end
end
end