Class: Pulitzer::UpdateVersionStatus

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(version, status) ⇒ UpdateVersionStatus

Returns a new instance of UpdateVersionStatus.



4
5
6
7
8
9
10
11
12
13
14
# File 'app/interactions/pulitzer/update_version_status.rb', line 4

def initialize(version, status)
  @errors = []
  @transitional_version = version
  @status = status
  @status_change_method = 'make_version_' + @status.to_s
  if @status == "active" && version.empty_required_content_elements?
    @processing_version = version
    @errors = ["It's not possible to activate a version without filling required content elements"]
  end
  @post = version.post
end

Instance Attribute Details

#errorsObject

Returns the value of attribute errors.



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

def errors
  @errors
end

Instance Method Details

#callObject



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

def call
  unless @errors.any?
    send @status_change_method
  end
  @processing_version
end

#make_version_abandonedObject



40
41
42
43
44
45
46
47
48
49
50
51
# File 'app/interactions/pulitzer/update_version_status.rb', line 40

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
    instance_eval(&Pulitzer.publish_callback) unless Pulitzer.skip_publish_callback?
  else
    @processing_version = @post.create_processing_version
    Pulitzer::CloneVersionJob.perform_later(@active_version)
    @processing_version
  end
end

#make_version_activeObject



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

def make_version_active
  @new_active_version = @transitional_version
  @old_active_version = @new_active_version.post.active_version
  begin
    @new_active_version.update!(status: :active)
  rescue ActiveRecord::RecordInvalid => invalid
    Rails.logger.error(invalid.record.errors.messages.to_s)
  end
  @new_active_version.tags.each &:touch
  @old_active_version.update(status: :archived) if @old_active_version
  @processing_version = @post.create_processing_version
  Pulitzer::CloneVersionJob.perform_later(@new_active_version)
  instance_eval(&Pulitzer.publish_callback) unless Pulitzer.skip_publish_callback?
  @post.reload
  @processing_version.reload
end