Class: Snapshot::ArticleVariant

Inherits:
ApplicationRecord
  • Object
show all
Defined in:
app/models/postnhost/snapshot/article_variant.rb

Constant Summary collapse

SCALAR_ATTRIBUTES =
%i[
  language_id title title_tag og_title schema_headline meta_description custom_excerpt auto_excerpt
  use_excerpt_as_meta_description content
].freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.matching(query) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
# File 'app/models/postnhost/snapshot/article_variant.rb', line 39

def self.matching(query)
  return all if query.blank?

  where(
    <<~SQL.squish,
      LOWER(postnhost_article_variant_snapshots.title) LIKE :search OR
      LOWER(postnhost_article_variant_snapshots.content) LIKE :search OR
      LOWER(postnhost_article_variant_snapshots.meta_description) LIKE :search
    SQL
    search: "%#{sanitize_sql_like(query.downcase)}%"
  )
end

Instance Method Details

#differs_from?(draft) ⇒ Boolean

Returns:

  • (Boolean)


56
57
58
# File 'app/models/postnhost/snapshot/article_variant.rb', line 56

def differs_from?(draft)
  SCALAR_ATTRIBUTES.any? { |attribute| public_send(attribute) != draft.public_send(attribute) }
end

#published?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'app/models/postnhost/snapshot/article_variant.rb', line 52

def published?
  true
end