Class: ImportExport::CategoryExporter

Inherits:
BaseExporter show all
Defined in:
lib/import_export/category_exporter.rb

Constant Summary

Constants inherited from BaseExporter

BaseExporter::CATEGORY_ATTRS, BaseExporter::GROUP_ATTRS, BaseExporter::POST_ATTRS, BaseExporter::TOPIC_ATTRS, BaseExporter::USER_ATTRS

Instance Attribute Summary

Attributes inherited from BaseExporter

#categories, #export_data

Instance Method Summary collapse

Methods inherited from BaseExporter

#export_categories, #export_categories!, #export_category_groups, #export_category_groups!, #export_group_users, #export_group_users!, #export_groups, #export_groups!, #export_topic_users, #export_topic_users!, #export_topics, #export_topics!, #export_translation_overrides, #export_users, #save_to_file

Constructor Details

#initialize(category_ids) ⇒ CategoryExporter

Returns a new instance of CategoryExporter.



8
9
10
11
12
# File 'lib/import_export/category_exporter.rb', line 8

def initialize(category_ids)
  @categories =
    Category.where(id: category_ids).or(Category.where(parent_category_id: category_ids)).to_a
  @export_data = { categories: [], groups: [], topics: [], users: [] }
end

Instance Method Details

#default_filename_prefixObject



34
35
36
# File 'lib/import_export/category_exporter.rb', line 34

def default_filename_prefix
  "category-export"
end

#export_topics_and_usersObject



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/import_export/category_exporter.rb', line 21

def export_topics_and_users
  all_category_ids = @categories.pluck(:id)
  description_topic_ids = @categories.pluck(:topic_id)
  topic_exporter =
    ImportExport::TopicExporter.new(
      Topic.where(category_id: all_category_ids).pluck(:id) - description_topic_ids,
    )
  topic_exporter.perform
  @export_data[:users] = topic_exporter.export_data[:users]
  @export_data[:topics] = topic_exporter.export_data[:topics]
  self
end

#performObject



14
15
16
17
18
19
# File 'lib/import_export/category_exporter.rb', line 14

def perform
  export_categories!
  export_category_groups!
  export_topics_and_users
  self
end