Sha256: 8284f23d194c852d9a58cd32af4934f46a489a56129c0c2bd9f4ef7c7fdd0939

Contents?: true

Size: 1003 Bytes

Versions: 54

Compression:

Stored size: 1003 Bytes

Contents

# frozen_string_literal: true

module Decidim
  module Admin
    # A command with all the business logic when updating a static page.
    class UpdateStaticPage < Rectify::Command
      # Public: Initializes the command.
      #
      # page - The StaticPage to update
      # form - A form object with the params.
      def initialize(page, form)
        @page = page
        @form = form
      end

      # Executes the command. Broadcasts these events:
      #
      # - :ok when everything is valid.
      # - :invalid if the form wasn't valid and we couldn't proceed.
      #
      # Returns nothing.
      def call
        return broadcast(:invalid) if form.invalid?

        update_page
        broadcast(:ok)
      end

      private

      attr_reader :form

      def update_page
        @page.update_attributes!(attributes)
      end

      def attributes
        {
          title: form.title,
          slug: form.slug,
          content: form.content
        }
      end
    end
  end
end

Version data entries

54 entries across 54 versions & 2 rubygems

Version Path
decidim-admin-0.9.3 app/commands/decidim/admin/update_static_page.rb
decidim-admin-0.9.2 app/commands/decidim/admin/update_static_page.rb
decidim-admin-0.9.1 app/commands/decidim/admin/update_static_page.rb
decidim-admin-0.9.0 app/commands/decidim/admin/update_static_page.rb
decidim-admin-0.8.4 app/commands/decidim/admin/update_static_page.rb
decidim-admin-0.8.3 app/commands/decidim/admin/update_static_page.rb
decidim-admin-0.8.2 app/commands/decidim/admin/update_static_page.rb
decidim-admin-0.8.1 app/commands/decidim/admin/update_static_page.rb
decidim-admin-0.8.0 app/commands/decidim/admin/update_static_page.rb
decidim-admin-0.7.4 app/commands/decidim/admin/update_static_page.rb
decidim-admin-0.7.3 app/commands/decidim/admin/update_static_page.rb
decidim-admin-0.7.2 app/commands/decidim/admin/update_static_page.rb
decidim-admin-0.7.1 app/commands/decidim/admin/update_static_page.rb
decidim-admin-0.7.0 app/commands/decidim/admin/update_static_page.rb
decidim-admin-0.6.8 app/commands/decidim/admin/update_static_page.rb
decidim-0.6.8 decidim-admin/app/commands/decidim/admin/update_static_page.rb
decidim-admin-0.6.7 app/commands/decidim/admin/update_static_page.rb
decidim-0.6.7 decidim-admin/app/commands/decidim/admin/update_static_page.rb
decidim-admin-0.6.6 app/commands/decidim/admin/update_static_page.rb
decidim-0.6.6 decidim-admin/app/commands/decidim/admin/update_static_page.rb