Class: Integral::Post

Inherits:
ApplicationRecord show all
Extended by:
FriendlyId
Includes:
ActionView::Helpers::DateHelper, BlockEditor::Listable, Webhook::Observable
Defined in:
app/models/integral/post.rb

Overview

Represents a user post

Instance Method Summary collapse

Methods included from Webhook::Delivery

#deliver_webhook, #deliver_webhook_event

Methods inherited from ApplicationRecord

available_statuses

Instance Method Details

#frontend_urlObject



83
84
85
86
# File 'app/models/integral/post.rb', line 83

def frontend_url
  route = Integral.multilingual_frontend? ? "post_#{locale}_url" : 'post_url'
  Integral::Engine.routes.url_helpers.send(route, slug)
end

#increment_count!(ip_address) ⇒ Object

Increments the view count of the post if a PostViewing is successfully added

Parameters:

  • ip_address (String)

    Viewers IP address



66
67
68
# File 'app/models/integral/post.rb', line 66

def increment_count!(ip_address)
  increment!(:view_count) if PostViewing.add(self, ip_address)
end

#tag_contextString

Returns Current tag context.

Returns:

  • (String)

    Current tag context



89
90
91
# File 'app/models/integral/post.rb', line 89

def tag_context
  "#{status}_#{locale}"
end

#tagsArray

Returns ActsAsTaggableOn::Tag tags associated with this post.

Returns:

  • (Array)

    ActsAsTaggableOn::Tag tags associated with this post



94
95
96
# File 'app/models/integral/post.rb', line 94

def tags
  tags_on(tag_context)
end

#to_list_itemHash

Returns the instance as a list item.

Returns:

  • (Hash)

    the instance as a list item



71
72
73
74
75
76
77
78
79
80
81
# File 'app/models/integral/post.rb', line 71

def to_list_item
  subtitle = published_at.present? ? I18n.t('integral.blog.posted_ago', time: time_ago_in_words(published_at)) : I18n.t('integral.statuses.draft')
  {
    id: id,
    title: title,
    subtitle: subtitle,
    description: description,
    image: featured_image&.attachment,
    url: frontend_url
  }
end

#to_paramObject



98
99
100
# File 'app/models/integral/post.rb', line 98

def to_param
  id
end