Class: Decidim::Blogs::Admin::CreatePost

Inherits:
Command
  • Object
show all
Defined in:
decidim-blogs/app/commands/decidim/blogs/admin/create_post.rb

Overview

This command is executed when the user creates a Post from the admin panel.

Instance Method Summary collapse

Methods inherited from Command

call, #evaluate, #method_missing, #respond_to_missing?, #transaction

Constructor Details

#initialize(form, current_user) ⇒ CreatePost

Returns a new instance of CreatePost.


9
10
11
12
# File 'decidim-blogs/app/commands/decidim/blogs/admin/create_post.rb', line 9

def initialize(form, current_user)
  @form = form
  @current_user = current_user
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Decidim::Command

Instance Method Details

#callObject

Creates the post if valid.

Broadcasts :ok if successful, :invalid otherwise.


17
18
19
20
21
22
23
24
25
26
# File 'decidim-blogs/app/commands/decidim/blogs/admin/create_post.rb', line 17

def call
  return broadcast(:invalid) if @form.invalid?

  transaction do
    create_post!
    send_notification
  end

  broadcast(:ok, @post)
end