Sha256: 6d54b710ce1c04613501ef897ac7e17bb8cd91477fa6641d79cf4917917e54ec
Contents?: true
Size: 959 Bytes
Versions: 48
Compression:
Stored size: 959 Bytes
Contents
# frozen_string_literal: true module Decidim # A command with all the business logic for when a user starts following a resource. class CreateFollow < 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? create_follow! broadcast(:ok, follow) end private attr_reader :follow, :form, :current_user def create_follow! @follow = Follow.create!( followable: form.followable, user: current_user ) end end end
Version data entries
48 entries across 48 versions & 2 rubygems