Class: Decidim::Blogs::Admin::UpdatePost

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

Overview

This command is executed when the user changes a Blog from the admin panel.

Instance Method Summary collapse

Methods inherited from Command

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

Constructor Details

#initialize(form, post) ⇒ UpdatePost

Initializes a UpdateBlog Command.

form - The form from which to get the data. blog - The current instance of the page to be updated.


13
14
15
16
# File 'decidim-blogs/app/commands/decidim/blogs/admin/update_post.rb', line 13

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

Dynamic Method Handling

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

Instance Method Details

#callObject

Updates the blog if valid.

Broadcasts :ok if successful, :invalid otherwise.


21
22
23
24
25
26
27
28
29
# File 'decidim-blogs/app/commands/decidim/blogs/admin/update_post.rb', line 21

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

  transaction do
    update_post!
  end

  broadcast(:ok, post)
end