Class: Articles::Unpublish

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

Instance Method Summary collapse

Constructor Details

#initialize(article:) ⇒ Unpublish

Returns a new instance of Unpublish.



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

def initialize(article:)
  @article = article
end

Instance Method Details

#callObject



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

def call
  snapshot = article.article_snapshot
  return failure("Article snapshot was not found", status: :not_found) unless snapshot

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