Class: Pulitzer::UpdateVersionStatus

Inherits:
Object
  • Object
show all
Defined in:
app/interactions/pulitzer/update_version_status.rb

Instance Method Summary collapse

Constructor Details

#initialize(version, status) ⇒ UpdateVersionStatus

Returns a new instance of UpdateVersionStatus.



2
3
4
5
6
7
# File 'app/interactions/pulitzer/update_version_status.rb', line 2

def initialize(version, status)
  @transitional_version = version
  @status = status
  @status_change_method = 'make_version_' + @status.to_s
  @post = version.post
end

Instance Method Details

#callObject



9
10
11
# File 'app/interactions/pulitzer/update_version_status.rb', line 9

def call
  send @status_change_method
end

#make_version_abandonedObject



23
24
25
26
27
28
29
30
31
32
33
# File 'app/interactions/pulitzer/update_version_status.rb', line 23

def make_version_abandoned
  @active_version = @transitional_version.post.active_version
  @transitional_version.update(status: :abandoned)
  if @active_version == @transitional_version
    @transitional_version.post.preview_version
  else
    @processing_version = @post.create_processing_version
    Pulitzer::CloneVersionJob.perform_later(@active_version)
    @processing_version
  end
end

#make_version_activeObject



13
14
15
16
17
18
19
20
21
# File 'app/interactions/pulitzer/update_version_status.rb', line 13

def make_version_active
  @new_active_version = @transitional_version
  @old_active_version = @new_active_version.post.active_version
  @new_active_version.update(status: :active)
  @old_active_version.update(status: :archived) if @old_active_version
  @processing_version = @post.create_processing_version
  Pulitzer::CloneVersionJob.perform_later(@new_active_version)
  @processing_version
end