Class: SyncMachine::EnsurePublication::PublicationHistory

Inherits:
Object
  • Object
show all
Defined in:
lib/sync_machine/ensure_publication/publication_history.rb

Overview

Manage logic around whether the document was previously published at all, and maintaining history for future jobs.

Instance Method Summary collapse

Constructor Details

#initialize(subject_id:, sync_module:) ⇒ PublicationHistory

Returns a new instance of PublicationHistory.



6
7
8
9
# File 'lib/sync_machine/ensure_publication/publication_history.rb', line 6

def initialize(subject_id:, sync_module:)
  @subject_id = subject_id
  @sync_module = sync_module
end

Instance Method Details

#last_job_finished_atObject



17
18
19
# File 'lib/sync_machine/ensure_publication/publication_history.rb', line 17

def last_job_finished_at
  previous_payload.try(:generated_at)
end

#last_publish_equals?(payload_body) ⇒ Boolean

Returns:

  • (Boolean)


11
12
13
14
15
# File 'lib/sync_machine/ensure_publication/publication_history.rb', line 11

def last_publish_equals?(payload_body)
  return false unless previous_payload
  HashWithIndifferentAccess.new(previous_payload.body) ==
    HashWithIndifferentAccess.new(payload_body)
end

#record_generation_timeObject



21
22
23
# File 'lib/sync_machine/ensure_publication/publication_history.rb', line 21

def record_generation_time
  previous_payload.update_attribute(:generated_at, Time.now)
end

#update(payload_body) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/sync_machine/ensure_publication/publication_history.rb', line 25

def update(payload_body)
  if previous_payload
    previous_payload.update_attributes(
      body: payload_body, generated_at: Time.now
    )
  else
    create_payload_record(payload_body)
  end
end