Class: Workarea::SavePublishing

Inherits:
Object
  • Object
show all
Defined in:
app/services/workarea/save_publishing.rb

Instance Method Summary collapse

Constructor Details

#initialize(releasable, params) ⇒ SavePublishing

Returns a new instance of SavePublishing.



5
6
7
8
# File 'app/services/workarea/save_publishing.rb', line 5

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

Instance Method Details

#activate?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'app/services/workarea/save_publishing.rb', line 30

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

#active_segment_idsObject



34
35
36
# File 'app/services/workarea/save_publishing.rb', line 34

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

#performObject



10
11
12
13
14
15
16
17
# File 'app/services/workarea/save_publishing.rb', line 10

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

#releaseObject



19
20
21
22
23
24
25
26
27
28
# File 'app/services/workarea/save_publishing.rb', line 19

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