module Mobile module Entities class User < Grape::Entity include ApplicationHelper include ApiHelper def self.user_expose(f) expose f do |u,opt| if u.is_a?(Hash) && u.key?(f) u[f] elsif u.is_a?(::User) if u.respond_to?(f) u.send(f) else case f when :img_url url_to_avatar(u) when :gender u.user_extensions.gender.nil? ? 0 : u.user_extensions.gender when :work_unit get_user_work_unit u when :location get_user_location u when :brief_introduction u.user_extensions.brief_introduction end end end end end expose :id #头像 user_expose :img_url #昵称 expose :nickname #性别 user_expose :gender #我的二维码 #工作单位 user_expose :work_unit #邮箱地址 user_expose :mail #地区 user_expose :location #签名 user_expose :brief_introduction end end end