Sha256: 70382962f9895d66304d6c52253cb6fed34e334224a82ce1802e4cc88ca2542b

Contents?: true

Size: 634 Bytes

Versions: 10

Compression:

Stored size: 634 Bytes

Contents

# frozen_string_literal: true
module Decidim
  module Admin
    # Delivers the newsletter to its recipients.
    class DeliverNewsletter < Rectify::Command
      # Initializes the command.
      #
      # newsletter - The newsletter to deliver.
      def initialize(newsletter)
        @newsletter = newsletter
      end

      def call
        @newsletter.with_lock do
          return broadcast(:invalid) if @newsletter.sent?
          send_newsletter!
        end

        broadcast(:ok, @newsletter)
      end

      private

      def send_newsletter!
        NewsletterJob.perform_later(@newsletter)
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
decidim-admin-0.1.0 app/commands/decidim/admin/deliver_newsletter.rb
decidim-0.1.0 decidim-admin/app/commands/decidim/admin/deliver_newsletter.rb
decidim-admin-0.0.8.1 app/commands/decidim/admin/deliver_newsletter.rb
decidim-0.0.8.1 decidim-admin/app/commands/decidim/admin/deliver_newsletter.rb
decidim-admin-0.0.7 app/commands/decidim/admin/deliver_newsletter.rb
decidim-0.0.7 decidim-admin/app/commands/decidim/admin/deliver_newsletter.rb
decidim-admin-0.0.6 app/commands/decidim/admin/deliver_newsletter.rb
decidim-0.0.6 decidim-admin/app/commands/decidim/admin/deliver_newsletter.rb
decidim-admin-0.0.5 app/commands/decidim/admin/deliver_newsletter.rb
decidim-0.0.5 decidim-admin/app/commands/decidim/admin/deliver_newsletter.rb