scinote-web/app/serializers/api/v1/user_serializer.rb

26 lines
589 B
Ruby
Raw Normal View History

# frozen_string_literal: true
2018-08-21 19:56:14 +08:00
module Api
module V1
class UserSerializer < ActiveModel::Serializer
type :users
2018-08-21 19:56:14 +08:00
attributes :full_name, :initials, :email
attribute :avatar_file_name, if: -> { object.avatar.present? }
attribute :avatar_file_size, if: -> { object.avatar.present? }
attribute :avatar_url, if: -> { object.avatar.present? }
def avatar_file_name
object.avatar_file_name
end
def avatar_file_size
object.avatar.size
end
def avatar_url
object.avatar.url(:icon)
end
2018-08-21 19:56:14 +08:00
end
end
end