Class: FlagSerializer

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

Instance Method Summary collapse

Methods inherited from ApplicationSerializer

expire_cache_fragment!, fragment_cache

Methods inherited from ActiveModel::Serializer

#include!

Instance Method Details

#applies_toObject



47
48
49
# File 'app/serializers/flag_serializer.rb', line 47

def applies_to
  Array.wrap(object.applies_to)
end

#descriptionObject



27
28
29
30
31
32
33
# File 'app/serializers/flag_serializer.rb', line 27

def description
  I18n.t(
    "#{i18n_prefix}.description",
    default: object.description.to_s,
    base_path: Discourse.base_path,
  )
end

#i18n_prefixObject



18
19
20
# File 'app/serializers/flag_serializer.rb', line 18

def i18n_prefix
  "#{@options[:target] || "post_action"}_types.#{object.name_key}"
end

#is_flagObject



39
40
41
# File 'app/serializers/flag_serializer.rb', line 39

def is_flag
  !object.score_type && object.id != PostActionType::LIKE_POST_ACTION_ID
end

#is_usedObject



43
44
45
# File 'app/serializers/flag_serializer.rb', line 43

def is_used
  @options[:used_flag_ids].include?(object.id)
end

#nameObject



22
23
24
25
# File 'app/serializers/flag_serializer.rb', line 22

def name
  # system flags are using i18n translations when custom flags are using value entered by admin
  I18n.t("#{i18n_prefix}.title", default: object.name)
end

#short_descriptionObject



35
36
37
# File 'app/serializers/flag_serializer.rb', line 35

def short_description
  I18n.t("#{i18n_prefix}.short_description", base_path: Discourse.base_path, default: "")
end