Class: CategoryDetailedSerializer

Inherits:
BasicCategorySerializer show all
Defined in:
app/serializers/category_detailed_serializer.rb

Instance Method Summary collapse

Methods inherited from BasicCategorySerializer

#can_edit, #custom_fields, #description, #description_excerpt, #description_text, #include_can_edit?, #include_custom_fields?, #include_parent_category_id?, #name, #notification_level

Methods inherited from ApplicationSerializer

expire_cache_fragment!, fragment_cache

Methods inherited from ActiveModel::Serializer

#include!

Instance Method Details

#count_with_subcategories(method) ⇒ Object



57
58
59
60
61
62
63
# File 'app/serializers/category_detailed_serializer.rb', line 57

def count_with_subcategories(method)
  count = object.public_send(method) || 0

  object.subcategories.each { |category| count += (category.public_send(method) || 0) }

  count
end

#include_displayable_topics?Boolean

Returns:

  • (Boolean)


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

def include_displayable_topics?
  displayable_topics.present?
end

#include_is_uncategorized?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'app/serializers/category_detailed_serializer.rb', line 33

def include_is_uncategorized?
  is_uncategorized
end

#include_subcategory_list?Boolean

Returns:

  • (Boolean)


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

def include_subcategory_list?
  subcategory_list.present?
end

#is_uncategorizedObject



29
30
31
# File 'app/serializers/category_detailed_serializer.rb', line 29

def is_uncategorized
  object.id == SiteSetting.uncategorized_category_id
end

#topics_all_timeObject



53
54
55
# File 'app/serializers/category_detailed_serializer.rb', line 53

def topics_all_time
  count_with_subcategories(:topic_count)
end

#topics_dayObject



37
38
39
# File 'app/serializers/category_detailed_serializer.rb', line 37

def topics_day
  count_with_subcategories(:topics_day)
end

#topics_monthObject



45
46
47
# File 'app/serializers/category_detailed_serializer.rb', line 45

def topics_month
  count_with_subcategories(:topics_month)
end

#topics_weekObject



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

def topics_week
  count_with_subcategories(:topics_week)
end

#topics_yearObject



49
50
51
# File 'app/serializers/category_detailed_serializer.rb', line 49

def topics_year
  count_with_subcategories(:topics_year)
end