Class: Postnhost::Publishing::RouteValidator

Inherits:
Object
  • Object
show all
Defined in:
app/services/postnhost/publishing/route_validator.rb

Constant Summary collapse

RESERVED_SLUGS =
%w[authors search sitemap.xml sitemap.xsl].freeze

Class Method Summary collapse

Class Method Details

.validate!(slug:, article_id: nil, page_id: nil) ⇒ Object

Raises:



6
7
8
9
10
11
12
13
# File 'app/services/postnhost/publishing/route_validator.rb', line 6

def self.validate!(slug:, article_id: nil, page_id: nil)
  errors = []
  errors << "slug has already been published by an article" if article_conflict?(slug, article_id)
  errors << "slug has already been published by a page" if page_conflict?(slug, page_id)
  errors << "slug conflicts with a category route" if Postnhost::Category.exists?(slug:)
  errors << "slug conflicts with a static route" if static_slugs.include?(slug)
  raise Error, errors if errors.any?
end