Sha256: 83f4a1a499b5038c16e4c52f51225ca5c9495e08a66c29123e5b7f4c2fc8a4fc

Contents?: true

Size: 1.16 KB

Versions: 32

Compression:

Stored size: 1.16 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,
          default_step_settings: form.default_step_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

32 entries across 32 versions & 2 rubygems

Version Path
decidim-admin-0.6.8 app/commands/decidim/admin/update_feature.rb
decidim-0.6.8 decidim-admin/app/commands/decidim/admin/update_feature.rb
decidim-admin-0.6.7 app/commands/decidim/admin/update_feature.rb
decidim-0.6.7 decidim-admin/app/commands/decidim/admin/update_feature.rb
decidim-admin-0.6.6 app/commands/decidim/admin/update_feature.rb
decidim-0.6.6 decidim-admin/app/commands/decidim/admin/update_feature.rb
decidim-admin-0.6.5 app/commands/decidim/admin/update_feature.rb
decidim-0.6.5 decidim-admin/app/commands/decidim/admin/update_feature.rb
decidim-admin-0.6.4 app/commands/decidim/admin/update_feature.rb
decidim-0.6.4 decidim-admin/app/commands/decidim/admin/update_feature.rb
decidim-admin-0.6.3 app/commands/decidim/admin/update_feature.rb
decidim-0.6.3 decidim-admin/app/commands/decidim/admin/update_feature.rb
decidim-admin-0.6.2 app/commands/decidim/admin/update_feature.rb
decidim-0.6.2 decidim-admin/app/commands/decidim/admin/update_feature.rb
decidim-admin-0.6.1 app/commands/decidim/admin/update_feature.rb
decidim-0.6.1 decidim-admin/app/commands/decidim/admin/update_feature.rb
decidim-admin-0.6.0 app/commands/decidim/admin/update_feature.rb
decidim-0.6.0 decidim-admin/app/commands/decidim/admin/update_feature.rb
decidim-admin-0.5.1 app/commands/decidim/admin/update_feature.rb
decidim-0.5.1 decidim-admin/app/commands/decidim/admin/update_feature.rb