Class: UserWithCustomFieldsSerializer

Inherits:
BasicUserSerializer show all
Defined in:
app/serializers/user_with_custom_fields_serializer.rb

Overview

A basic user serializer, with custom fields

Instance Method Summary collapse

Methods inherited from BasicUserSerializer

#avatar_template, #categories_with_notification_level, #category_user_notification_levels, #include_name?, #name, #user, #user_is_current_user

Methods inherited from ApplicationSerializer

expire_cache_fragment!, fragment_cache

Methods inherited from ActiveModel::Serializer

#include!

Instance Method Details

#custom_fieldsObject



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'app/serializers/user_with_custom_fields_serializer.rb', line 7

def custom_fields
  fields = custom_field_keys

  if fields.present?
    if object.custom_fields_preloaded?
      {}.tap { |h| fields.each { |f| h[f] = object.custom_fields[f] } }
    else
      User.custom_fields_for_ids([object.id], fields)[object.id] || {}
    end
  else
    {}
  end
end