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

26 lines
606 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
2019-07-26 21:58:51 +08:00
attribute :avatar_file_name, if: -> { object.avatar.attached? }
attribute :avatar_file_size, if: -> { object.avatar.attached? }
attribute :avatar_url, if: -> { object.avatar.attached? }
def avatar_file_name
2019-07-26 21:58:51 +08:00
object.avatar.blob.filename
end
def avatar_file_size
2019-07-26 21:58:51 +08:00
object.avatar.blob.byte_size
end
def avatar_url
2019-07-26 21:58:51 +08:00
object.avatar_url(:icon)
end
2018-08-21 19:56:14 +08:00
end
end
end