Sha256: ba87cbd9aef0f6564fcdb62316f0066ed3c0e5617435207e91a9a9c3d450cbe5

Contents?: true

Size: 1.13 KB

Versions: 27

Compression:

Stored size: 1.13 KB

Contents

# frozen_string_literal: true

module Thredded
  # Creates a new messageboard and seeds it with a topic.
  class CreateMessageboard
    # @param messageboard [Thredded::Messageboard]
    # @param user [Thredded.user_class]
    def initialize(messageboard, user)
      @messageboard = messageboard
      @user = user
    end

    # @return [boolean] true if the messageboard was created and seeded with a topic successfully.
    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

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

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

Version data entries

27 entries across 27 versions & 2 rubygems

Version Path
thredded-1.0.0 app/commands/thredded/create_messageboard.rb
thredded-0.16.16 app/commands/thredded/create_messageboard.rb
thredded-0.16.15 app/commands/thredded/create_messageboard.rb
thredded-0.16.14 app/commands/thredded/create_messageboard.rb
thredded-0.16.13 app/commands/thredded/create_messageboard.rb
thredded-0.16.12 app/commands/thredded/create_messageboard.rb
thredded-0.16.11 app/commands/thredded/create_messageboard.rb
thredded-0.16.10 app/commands/thredded/create_messageboard.rb
thredded-0.16.9 app/commands/thredded/create_messageboard.rb
thredded-0.16.8 app/commands/thredded/create_messageboard.rb
thredded-0.16.7 app/commands/thredded/create_messageboard.rb
thredded-0.16.6 app/commands/thredded/create_messageboard.rb
thredded-0.16.5 app/commands/thredded/create_messageboard.rb
thredded-0.16.4 app/commands/thredded/create_messageboard.rb
thredded-0.16.3 app/commands/thredded/create_messageboard.rb
thredded-0.16.1 app/commands/thredded/create_messageboard.rb
thredded-0.16.0 app/commands/thredded/create_messageboard.rb
thredded-0.15.5 app/commands/thredded/create_messageboard.rb
thredded-0.15.4 app/commands/thredded/create_messageboard.rb
thredded-0.15.3 app/commands/thredded/create_messageboard.rb