Sha256: fd20c023bb8025d338c0bd473bf3ad53ff6767ede319663e01ad9d3a309f9283

Contents?: true

Size: 1.14 KB

Versions: 2

Compression:

Stored size: 1.14 KB

Contents

# frozen_string_literal: true

module Decidim
  module ComparativeStats
    module Admin
      # A command with all the business logic when updating an endpoint
      class UpdateEndpoint < Rectify::Command
        # Public: Initializes the command.
        #
        # form - A form object with the params.
        def initialize(endpoint, form, user)
          @endpoint = endpoint
          @form = form
          @user = user
        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_endpoint!
          broadcast(:ok)
        end

        private

        attr_reader :form

        def update_endpoint!
          Decidim.traceability.update!(
            @endpoint,
            @user,
            endpoint: form.endpoint,
            name: form.name,
            api_version: form.context.api.name_and_version.version,
            active: form.active
          )
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
decidim-comparative_stats-1.1.0 app/commands/decidim/comparative_stats/admin/update_endpoint.rb
decidim-comparative_stats-1.0.1 app/commands/decidim/comparative_stats/admin/update_endpoint.rb