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
15
16
17
18
19
# 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?
    @errors = ["It's not possible to activate a version without filling required content elements"]
  end
  if @status == "active" && !version.required_partials?
    @errors = ["It's not possible to activate a version without the required partials"]
  end
  if @errors.any?
    @processing_version = version
  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



21
22
23
24
25
26
# File 'app/interactions/pulitzer/update_version_status.rb', line 21

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

#make_version_abandonedObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'app/interactions/pulitzer/update_version_status.rb', line 46

def make_version_abandoned
  @active_version = @transitional_version.post.active_version
  @transitional_version.update(status: :abandoned)
  @transitional_version.tags.each &:touch
  if @active_version.is_a? Pulitzer::Version
    if @active_version == @transitional_version
      @processing_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
  else # There is no active version, we never published this one
    @processing_version = nil
    @transitional_version.post.destroy
  end
  @transitional_version
end

#make_version_activeObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/interactions/pulitzer/update_version_status.rb', line 28

def make_version_active
  @new_active_version = @transitional_version
  @old_active_version = @new_active_version.post.active_version
  @new_active_version.update(status: :active)
  if @new_active_version.errors.any?
    @new_active_version.update(status: :processing_failed, cloning_errors: @new_active_version.errors.full_messages)
    @processing_version = @new_active_version
  else
    @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?
  end
  @post.reload
  @processing_version.reload
end