Class: Thredded::CreateMessageboard

Inherits:
Object
  • Object
show all
Defined in:
app/commands/thredded/create_messageboard.rb

Overview

Creates a new messageboard and seeds it with a topic.

Instance Method Summary collapse

Constructor Details

#initialize(messageboard, user) ⇒ CreateMessageboard

Returns a new instance of CreateMessageboard.

Parameters:



8
9
10
11
# File 'app/commands/thredded/create_messageboard.rb', line 8

def initialize(messageboard, user)
  @messageboard = messageboard
  @user = user
end

Instance Method Details

#first_topic_contentObject



36
37
38
39
40
# File 'app/commands/thredded/create_messageboard.rb', line 36

def first_topic_content
  <<~MARKDOWN
    #{I18n.t('thredded.messageboard_first_topic.content', thredded_version: Thredded::VERSION)}
  MARKDOWN
end

#first_topic_titleObject



32
33
34
# File 'app/commands/thredded/create_messageboard.rb', line 32

def first_topic_title
  I18n.t('thredded.messageboard_first_topic.title')
end

#runboolean

Returns true if the messageboard was created and seeded with a topic successfully.

Returns:

  • (boolean)

    true if the messageboard was created and seeded with a topic successfully.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/commands/thredded/create_messageboard.rb', line 14

def run
  Thredded::Messageboard.transaction do
    fail ActiveRecord::Rollback unless @messageboard.save
    topic = Thredded::Topic.create!(
      messageboard: @messageboard,
      user: @user,
      title: first_topic_title
    )
    Thredded::Post.create!(
      messageboard: @messageboard,
      user: @user,
      postable: topic,
      content: first_topic_content
    )
    true
  end
end