Class: Pages::Unpublish

Inherits:
BaseService
  • Object
show all
Defined in:
app/services/postnhost/publishing/pages/unpublish.rb

Instance Method Summary collapse

Constructor Details

#initialize(page:) ⇒ Unpublish

Returns a new instance of Unpublish.



4
5
6
# File 'app/services/postnhost/publishing/pages/unpublish.rb', line 4

def initialize(page:)
  @page = page
end

Instance Method Details

#callObject



8
9
10
11
12
13
14
15
16
17
18
19
# File 'app/services/postnhost/publishing/pages/unpublish.rb', line 8

def call
  snapshot = page.page_snapshot
  return failure("Page snapshot was not found", status: :not_found) unless snapshot

  Revision.hold do
    page.lock!
    snapshot.destroy!
  end
  success(true, status: :ok)
rescue ActiveRecord::RecordInvalid => e
  failure(e.message)
end