Class: Integral::Post
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Integral::Post
- Extended by:
- FriendlyId
- Includes:
- ActionView::Helpers::DateHelper
- Defined in:
- app/models/integral/post.rb
Overview
Represents a user post
Class Method Summary collapse
-
.available_statuses(opts = { reverse: false }) ⇒ Array
Containing available human readable statuses against there numeric value.
-
.listable_options ⇒ Hash
Listable options to be used within a RecordSelector widget.
Instance Method Summary collapse
-
#increment_count!(ip_address) ⇒ Object
Increments the view count of the post if a PostViewing is successfully added.
-
#tag_context ⇒ String
Current tag context.
-
#tags ⇒ Array
ActsAsTaggableOn::Tag tags associated with this post.
-
#to_card ⇒ Hash
The instance as a card.
-
#to_list_item ⇒ Hash
The instance as a list item.
-
#url ⇒ String
URL to frontend route.
Class Method Details
.available_statuses(opts = { reverse: false }) ⇒ Array
Returns containing available human readable statuses against there numeric value.
42 43 44 45 46 47 48 49 |
# File 'app/models/integral/post.rb', line 42 def self.available_statuses(opts = { reverse: false }) statuses = [ [I18n.t('integral.records.status.draft'), 0], [I18n.t('integral.records.status.published'), 1] ] opts[:reverse] ? statuses.each(&:reverse!) : statuses end |
.listable_options ⇒ Hash
Returns listable options to be used within a RecordSelector widget.
93 94 95 96 97 98 99 100 |
# File 'app/models/integral/post.rb', line 93 def self. { icon: 'rss', record_title: I18n.t('integral.backend.record_selector.posts.record'), selector_path: Engine.routes.url_helpers.backend_posts_path, selector_title: I18n.t('integral.backend.record_selector.posts.title') } end |
Instance Method Details
#increment_count!(ip_address) ⇒ Object
Increments the view count of the post if a PostViewing is successfully added
54 55 56 |
# File 'app/models/integral/post.rb', line 54 def increment_count!(ip_address) increment!(:view_count) if PostViewing.add(self, ip_address) end |
#tag_context ⇒ String
Returns Current tag context.
103 104 105 |
# File 'app/models/integral/post.rb', line 103 def tag_context status end |
#tags ⇒ Array
Returns ActsAsTaggableOn::Tag tags associated with this post.
108 109 110 |
# File 'app/models/integral/post.rb', line 108 def (tag_context) end |
#to_card ⇒ Hash
Returns the instance as a card.
72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'app/models/integral/post.rb', line 72 def to_card image_url = featured_image.file.url if featured_image { image: image_url, description: title, url: url, attributes: [ { key: I18n.t('integral.records.attributes.author'), value: .name }, { key: I18n.t('integral.records.attributes.views'), value: view_count }, { key: I18n.t('integral.records.attributes.status'), value: I18n.t("integral.records.status.#{status}") }, { key: I18n.t('integral.records.attributes.updated_at'), value: I18n.l(updated_at) } ] } end |
#to_list_item ⇒ Hash
Returns the instance as a list item.
59 60 61 62 63 64 65 66 67 68 69 |
# File 'app/models/integral/post.rb', line 59 def to_list_item subtitle = published_at.present? ? I18n.t('integral.blog.posted_ago', time: time_ago_in_words(published_at)) : I18n.t('integral.users.status.draft') { id: id, title: title, subtitle: subtitle, description: description, image: featured_image, url: Integral::Engine.routes.url_helpers.post_url(self) } end |