Class: PostComment

Inherits:
ApplicationRecord show all
Includes:
ActionView::Helpers::SanitizeHelper, Models::Auditable, RouteUrlHelpers
Defined in:
app/models/post_comment.rb

Overview

== Schema Information

Table name: post_comments
Database name: primary

id :integer not null, primary key
body :text
email :string(255)
name :string(255)
referrer :string(500)
site_url :string(255)
state :string(20) default("new"), not null
user_agent :string(255)
user_ip :string(255)
created_at :datetime
blogger_id :string(255)
parent_comment_id :integer
post_id :integer
user_id :integer

Indexes

idx_parent_comment_id (parent_comment_id)
idx_post_id_where_pc_is_null (post_id) WHERE (parent_comment_id IS NULL)
idx_state_parent_comment_id (state,parent_comment_id)
index_post_comments_on_post_id_and_created_at (post_id,created_at)

Constant Summary

Constants included from Models::Auditable

Models::Auditable::ALWAYS_IGNORED

Constants included from RouteUrlHelpers

RouteUrlHelpers::ROUTES

Constants included from Models::Schedulable

Models::Schedulable::SIMPLE_FORM_OPTIONS

Instance Attribute Summary collapse

Belongs to collapse

Methods included from Models::Auditable

#creator, #updater

Has many collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Models::Auditable

#all_skipped_columns, #audit_reference_data, #should_not_save_version, #stamp_record

Methods inherited from ApplicationRecord

ransackable_associations, ransackable_attributes, ransackable_scopes, ransortable_attributes, #to_relation

Methods included from Models::Schedulable

config

Methods included from Models::AfterCommittable

#after_commit

Methods included from Models::EventPublishable

#publish_event

Instance Attribute Details

#bodyString (readonly)

Returns:

  • (String)


46
# File 'app/models/post_comment.rb', line 46

validates :body, presence: true

#hostObject

Returns the value of attribute host.



54
55
56
# File 'app/models/post_comment.rb', line 54

def host
  @host
end

Class Method Details

.only_parentsActiveRecord::Relation<PostComment>

A relation of PostComments that are only parents. Active Record Scope

Returns:

See Also:



51
# File 'app/models/post_comment.rb', line 51

scope :only_parents, -> { where(parent_comment_id: nil) }

.publishedActiveRecord::Relation<PostComment>

A relation of PostComments that are published. Active Record Scope

Returns:

See Also:



52
# File 'app/models/post_comment.rb', line 52

scope :published, -> { where(state: 'published') }

.states_for_selectvoid

This method returns an undefined value.



80
81
82
# File 'app/models/post_comment.rb', line 80

def self.states_for_select
  state_machines[:state].states.map { |s| [s.human_name.capitalize, s.value] }
end

Instance Method Details

#can_publish?Boolean

Returns:

  • (Boolean)


85
86
87
# File 'app/models/post_comment.rb', line 85

def can_publish?
  parent_comment.nil? || parent_comment&.published?
end

#childvoid

This method returns an undefined value.



131
132
133
# File 'app/models/post_comment.rb', line 131

def child
  child_comments.first
end

#child_commentsActiveRecord::Relation<PostComment>

Returns:



43
# File 'app/models/post_comment.rb', line 43

has_many :child_comments, -> { order(:created_at) }, class_name: 'PostComment', foreign_key: :parent_comment_id

#formatted_created_atvoid

This method returns an undefined value.



90
91
92
# File 'app/models/post_comment.rb', line 90

def formatted_created_at
  created_at.strftime('%A, %B %e, %Y')
end

#make_html_safevoid

This method returns an undefined value.



115
116
117
118
119
120
121
122
123
# File 'app/models/post_comment.rb', line 115

def make_html_safe
  # puts "make_html_safe, BEFORE: #{body}"
  self.body = sanitize(body).to_s.html_safe
  # puts "make_html_safe, AFTER: #{body}"
  self.site_url = sanitize(site_url).to_s.html_safe if site_url
  self.name = sanitize(name).to_s.html_safe if name
  self.email = sanitize(email).to_s.html_safe if email
  true
end

#parent_commentPostComment?

Returns:



40
# File 'app/models/post_comment.rb', line 40

belongs_to :parent_comment, class_name: 'PostComment', optional: true

#parsed_bodyvoid

This method returns an undefined value.



95
96
97
# File 'app/models/post_comment.rb', line 95

def parsed_body
  body
end

#postPost?

Returns:



38
# File 'app/models/post_comment.rb', line 38

belongs_to :post, optional: true

#request=(request) ⇒ void

This method returns an undefined value.

Sets request metadata for tracking purposes

Parameters:

  • request (Object)


107
108
109
110
111
112
# File 'app/models/post_comment.rb', line 107

def request=(request)
  self.user_ip = request.remote_ip
  self.user_agent = request.env['HTTP_USER_AGENT']
  self.referrer   = request.env['HTTP_REFERER']
  self.host = request.host_with_port
end

#send_alertvoid

This method returns an undefined value.



126
127
128
# File 'app/models/post_comment.rb', line 126

def send_alert
  SystemMailer.blog_comment(self).deliver_later
end

#states_for_selectvoid

This method returns an undefined value.



75
76
77
# File 'app/models/post_comment.rb', line 75

def states_for_select
  state_transitions.map(&:event).sort
end

#userParty?

Returns:



36
# File 'app/models/post_comment.rb', line 36

belongs_to :user, class_name: 'Party', optional: true

#user_namevoid

This method returns an undefined value.



100
101
102
# File 'app/models/post_comment.rb', line 100

def user_name
  user ? user.name : name
end