Class: BasicPostSerializer

Inherits:
ApplicationSerializer show all
Defined in:
app/serializers/basic_post_serializer.rb

Overview

The most basic attributes of a topic that we need to create a link for it.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from ApplicationSerializer

expire_cache_fragment!, fragment_cache

Methods inherited from ActiveModel::Serializer

#include!

Instance Attribute Details

#topic_viewObject

Returns the value of attribute topic_view.



7
8
9
# File 'app/serializers/basic_post_serializer.rb', line 7

def topic_view
  @topic_view
end

Instance Method Details

#avatar_templateObject



17
18
19
# File 'app/serializers/basic_post_serializer.rb', line 17

def avatar_template
  object.user && object.user.avatar_template
end

#cookedObject



29
30
31
32
33
34
35
36
37
38
39
# File 'app/serializers/basic_post_serializer.rb', line 29

def cooked
  if cooked_hidden
    if scope.current_user && object.user_id == scope.current_user.id
      I18n.t("flagging.you_must_edit", path: "/my/messages")
    else
      I18n.t("flagging.user_must_edit")
    end
  else
    object.filter_quotes(@parent_post)
  end
end

#cooked_hiddenObject



21
22
23
# File 'app/serializers/basic_post_serializer.rb', line 21

def cooked_hidden
  object.hidden && !scope.is_staff?
end

#include_cooked_hidden?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'app/serializers/basic_post_serializer.rb', line 25

def include_cooked_hidden?
  cooked_hidden
end

#include_name?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'app/serializers/basic_post_serializer.rb', line 41

def include_name?
  SiteSetting.enable_names?
end

#nameObject



9
10
11
# File 'app/serializers/basic_post_serializer.rb', line 9

def name
  object.user && object.user.name
end

#post_custom_fieldsObject



45
46
47
48
49
50
51
52
# File 'app/serializers/basic_post_serializer.rb', line 45

def post_custom_fields
  @post_custom_fields ||=
    if @topic_view
      (@topic_view.post_custom_fields || {})[object.id] || {}
    else
      object.custom_fields
    end
end

#usernameObject



13
14
15
# File 'app/serializers/basic_post_serializer.rb', line 13

def username
  object.user && object.user.username
end