Sha256: 7879d5a6d7021f6d1a617c40145ca5512851f878449d2909589e2d99e4188ff7

Contents?: true

Size: 864 Bytes

Versions: 48

Compression:

Stored size: 864 Bytes

Contents

# frozen_string_literal: true

module Decidim
  # A command with all the business logic for when a user stops following a resource.
  class DeleteFollow < Rectify::Command
    # Public: Initializes the command.
    #
    # form         - A form object with the params.
    # current_user - The current user.
    def initialize(form, current_user)
      @form = form
      @current_user = current_user
    end

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

      delete_follow!

      broadcast(:ok)
    end

    private

    attr_reader :form, :current_user

    def delete_follow!
      form.follow.destroy!
    end
  end
end

Version data entries

48 entries across 48 versions & 2 rubygems

Version Path
decidim-core-0.14.4 app/commands/decidim/delete_follow.rb
decidim-core-0.14.3 app/commands/decidim/delete_follow.rb
decidim-core-0.14.2 app/commands/decidim/delete_follow.rb
decidim-core-0.14.1 app/commands/decidim/delete_follow.rb
decidim-core-0.13.1 app/commands/decidim/delete_follow.rb
decidim-core-0.12.2 app/commands/decidim/delete_follow.rb
decidim-core-0.13.0 app/commands/decidim/delete_follow.rb
decidim-core-0.12.1 app/commands/decidim/delete_follow.rb
decidim-core-0.13.0.pre1 app/commands/decidim/delete_follow.rb
decidim-core-0.12.0 app/commands/decidim/delete_follow.rb
decidim-core-0.11.2 app/commands/decidim/delete_follow.rb
decidim-core-0.12.0.pre app/commands/decidim/delete_follow.rb
decidim-core-0.11.1 app/commands/decidim/delete_follow.rb
decidim-core-0.11.0.pre1 app/commands/decidim/delete_follow.rb
decidim-core-0.10.1 app/commands/decidim/delete_follow.rb
decidim-core-0.10.0 app/commands/decidim/delete_follow.rb
decidim-core-0.9.3 app/commands/decidim/delete_follow.rb
decidim-core-0.9.2 app/commands/decidim/delete_follow.rb
decidim-core-0.9.1 app/commands/decidim/delete_follow.rb
decidim-core-0.9.0 app/commands/decidim/delete_follow.rb