Sha256: 9bb7b9da3d1b8bac65a941ad24a790d7d95ce95f06cd94be45c174085ab10657

Contents?: true

Size: 1.1 KB

Versions: 8

Compression:

Stored size: 1.1 KB

Contents

# frozen_string_literal: true

module Decidim
  module Admin
    # This command gets called when a feature is created from the admin panel.
    class UpdateFeature < Rectify::Command
      attr_reader :form, :feature

      # Public: Initializes the command.
      #
      # form    - The form from which the data in this feature comes from.
      # feature - The feature to update.
      def initialize(form, feature)
        @manifest = feature.manifest
        @form = form
        @feature = feature
      end

      # Public: Creates the Feature.
      #
      # Broadcasts :ok if created, :invalid otherwise.
      def call
        return broadcast(:invalid) if form.invalid?

        transaction do
          update_feature
          run_hooks
        end

        broadcast(:ok)
      end

      private

      def update_feature
        @feature.update_attributes(
          name: form.name,
          settings: form.settings,
          step_settings: form.step_settings,
          weight: form.weight
        )
      end

      def run_hooks
        @manifest.run_hooks(:update, @feature)
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 2 rubygems

Version Path
decidim-admin-0.3.2 app/commands/decidim/admin/update_feature.rb
decidim-0.3.2 decidim-admin/app/commands/decidim/admin/update_feature.rb
decidim-admin-0.3.1 app/commands/decidim/admin/update_feature.rb
decidim-0.3.1 decidim-admin/app/commands/decidim/admin/update_feature.rb
decidim-admin-0.3.0 app/commands/decidim/admin/update_feature.rb
decidim-0.3.0 decidim-admin/app/commands/decidim/admin/update_feature.rb
decidim-admin-0.2.0 app/commands/decidim/admin/update_feature.rb
decidim-0.2.0 decidim-admin/app/commands/decidim/admin/update_feature.rb