Class: SyncMachine::EnsurePublication::PublicationHistory
- Inherits:
-
Object
- Object
- SyncMachine::EnsurePublication::PublicationHistory
- 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
-
#initialize(subject_id:, sync_module:) ⇒ PublicationHistory
constructor
A new instance of PublicationHistory.
- #last_job_finished_at ⇒ Object
- #last_publish_equals?(payload_body) ⇒ Boolean
- #record_generation_time ⇒ Object
- #update(payload_body) ⇒ Object
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_at ⇒ Object
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
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_time ⇒ Object
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 |