Class: SeedData::Topics
- Inherits:
-
Object
- Object
- SeedData::Topics
- Defined in:
- lib/seed_data/topics.rb
Class Method Summary collapse
Instance Method Summary collapse
- #create(site_setting_names: nil, include_welcome_topics: true, include_legal_topics: false) ⇒ Object
- #delete(site_setting_names: nil, skip_changed: false) ⇒ Object
-
#initialize(locale) ⇒ Topics
constructor
A new instance of Topics.
- #reseed_options ⇒ Object
- #update(site_setting_names: nil, skip_changed: false) ⇒ Object
Constructor Details
#initialize(locale) ⇒ Topics
Returns a new instance of Topics.
9 10 11 |
# File 'lib/seed_data/topics.rb', line 9 def initialize(locale) @locale = locale end |
Class Method Details
.with_default_locale ⇒ Object
5 6 7 |
# File 'lib/seed_data/topics.rb', line 5 def self.with_default_locale SeedData::Topics.new(SiteSetting.default_locale) end |
Instance Method Details
#create(site_setting_names: nil, include_welcome_topics: true, include_legal_topics: false) ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'lib/seed_data/topics.rb', line 13 def create(site_setting_names: nil, include_welcome_topics: true, include_legal_topics: false) I18n.with_locale(@locale) do topics( site_setting_names: site_setting_names, include_welcome_topics: include_welcome_topics, include_legal_topics: include_legal_topics || SiteSetting.company_name.present?, ).each { |params| create_topic(**params) } end end |
#delete(site_setting_names: nil, skip_changed: false) ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/seed_data/topics.rb', line 34 def delete(site_setting_names: nil, skip_changed: false) I18n.with_locale(@locale) do topics(site_setting_names: site_setting_names).each do |params| delete_topic(**params.slice(:site_setting_name), skip_changed: skip_changed) end end end |
#reseed_options ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/seed_data/topics.rb', line 42 def I18n.with_locale(@locale) do topics(require_existing_categories: false) .map do |params| post = find_post(params[:site_setting_name]) next unless post { id: params[:site_setting_name], name: post.topic.title, selected: unchanged?(post) } end .compact end end |
#update(site_setting_names: nil, skip_changed: false) ⇒ Object
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/seed_data/topics.rb', line 23 def update(site_setting_names: nil, skip_changed: false) I18n.with_locale(@locale) do topics( site_setting_names: site_setting_names, require_existing_categories: false, ).each do |params| update_topic(**params.except(:category, :after_create), skip_changed: skip_changed) end end end |