Sha256: 8603838ad1e755d19efd4606f1802d9bcc39745380fc414a6cc4f22b6fb41c99

Contents?: true

Size: 978 Bytes

Versions: 44

Compression:

Stored size: 978 Bytes

Contents

# frozen_string_literal: true

module Decidim
  module Blogs
    module Admin
      # This command is executed when the user changes a Blog from the admin
      # panel.
      class UpdatePost < Rectify::Command
        # Initializes a UpdateBlog Command.
        #
        # form - The form from which to get the data.
        # blog - The current instance of the page to be updated.
        def initialize(form, post)
          @form = form
          @post = post
        end

        # Updates the blog if valid.
        #
        # Broadcasts :ok if successful, :invalid otherwise.
        def call
          return broadcast(:invalid) if form.invalid?

          transaction do
            update_post!
          end

          broadcast(:ok, post)
        end

        private

        attr_reader :form, :post

        def update_post!
          post.update!(
            title: form.title,
            body: form.body
          )
        end
      end
    end
  end
end

Version data entries

44 entries across 44 versions & 1 rubygems

Version Path
decidim-blogs-0.24.3 app/commands/decidim/blogs/admin/update_post.rb
decidim-blogs-0.23.6 app/commands/decidim/blogs/admin/update_post.rb
decidim-blogs-0.24.2 app/commands/decidim/blogs/admin/update_post.rb
decidim-blogs-0.23.5 app/commands/decidim/blogs/admin/update_post.rb
decidim-blogs-0.24.1 app/commands/decidim/blogs/admin/update_post.rb
decidim-blogs-0.24.0 app/commands/decidim/blogs/admin/update_post.rb
decidim-blogs-0.24.0.rc2 app/commands/decidim/blogs/admin/update_post.rb
decidim-blogs-0.23.4 app/commands/decidim/blogs/admin/update_post.rb
decidim-blogs-0.24.0.rc1 app/commands/decidim/blogs/admin/update_post.rb
decidim-blogs-0.23.3 app/commands/decidim/blogs/admin/update_post.rb
decidim-blogs-0.23.2 app/commands/decidim/blogs/admin/update_post.rb
decidim-blogs-0.23.1 app/commands/decidim/blogs/admin/update_post.rb
decidim-blogs-0.23.1.rc1 app/commands/decidim/blogs/admin/update_post.rb
decidim-blogs-0.23.0 app/commands/decidim/blogs/admin/update_post.rb
decidim-blogs-0.22.0 app/commands/decidim/blogs/admin/update_post.rb
decidim-blogs-0.21.0 app/commands/decidim/blogs/admin/update_post.rb
decidim-blogs-0.20.1 app/commands/decidim/blogs/admin/update_post.rb
decidim-blogs-0.20.0 app/commands/decidim/blogs/admin/update_post.rb
decidim-blogs-0.19.1 app/commands/decidim/blogs/admin/update_post.rb
decidim-blogs-0.18.1 app/commands/decidim/blogs/admin/update_post.rb