Sha256: 40b43d12af1b28c07fc258b50bf054474fb3da7cd7d8ea81d99fafaef798b71b

Contents?: true

Size: 876 Bytes

Versions: 28

Compression:

Stored size: 876 Bytes

Contents

module Workarea
  class SavePublishing
    delegate :errors, to: :release, allow_nil: true

    def initialize(releasable, params)
      @releasable = releasable
      @params = params
    end

    def perform
      return false if release.present? && !release.valid?
      return true if @releasable.blank?

      Release.with_current(release.try(:id)) do
        @releasable.update!(active: activate?, active_segment_ids: active_segment_ids)
      end
    end

    def release
      return if @params[:activate].in?(%w(now never))

      @release ||=
        if @params[:activate] == 'new_release'
          Release.create(@params[:release])
        else
          Release.find(@params[:activate])
        end
    end

    def activate?
      @params[:activate] != 'never'
    end

    def active_segment_ids
      Array.wrap(@params[:active_segment_ids])
    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
workarea-core-3.5.6 app/services/workarea/save_publishing.rb
workarea-core-3.5.5 app/services/workarea/save_publishing.rb
workarea-core-3.5.4 app/services/workarea/save_publishing.rb
workarea-core-3.5.3 app/services/workarea/save_publishing.rb
workarea-core-3.5.2 app/services/workarea/save_publishing.rb
workarea-core-3.5.1 app/services/workarea/save_publishing.rb
workarea-core-3.5.0 app/services/workarea/save_publishing.rb
workarea-core-3.5.0.beta.1 app/services/workarea/save_publishing.rb