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.27 app/services/workarea/save_publishing.rb
workarea-core-3.5.26 app/services/workarea/save_publishing.rb
workarea-core-3.5.25 app/services/workarea/save_publishing.rb
workarea-core-3.5.23 app/services/workarea/save_publishing.rb
workarea-core-3.5.22 app/services/workarea/save_publishing.rb
workarea-core-3.5.21 app/services/workarea/save_publishing.rb
workarea-core-3.5.20 app/services/workarea/save_publishing.rb
workarea-core-3.5.19 app/services/workarea/save_publishing.rb
workarea-core-3.5.18 app/services/workarea/save_publishing.rb
workarea-core-3.5.17 app/services/workarea/save_publishing.rb
workarea-core-3.5.16 app/services/workarea/save_publishing.rb
workarea-core-3.5.15 app/services/workarea/save_publishing.rb
workarea-core-3.5.14 app/services/workarea/save_publishing.rb
workarea-core-3.5.13 app/services/workarea/save_publishing.rb
workarea-core-3.5.12 app/services/workarea/save_publishing.rb
workarea-core-3.5.11 app/services/workarea/save_publishing.rb
workarea-core-3.5.10 app/services/workarea/save_publishing.rb
workarea-core-3.5.9 app/services/workarea/save_publishing.rb
workarea-core-3.5.8 app/services/workarea/save_publishing.rb
workarea-core-3.5.7 app/services/workarea/save_publishing.rb