# frozen_string_literal: true class Post < ApplicationRecord include PublicIdConcern ########################################### # Attributes attribute :public_id, :public_id attribute :created_by_user_id, :integer attribute :role_visibility, :roles_as_array enum :status, {archived: 0, draft: 1, active: 2}, _prefix: true attribute :title, :text attribute :content, :string attribute :created_at, :datetime attribute :updated_at, :datetime attribute :posted_at, :datetime ########################################### # Associations has_many :post_files, dependent: :destroy has_many :files, through: :post_files ########################################### # Scopes ########################################### def published_at created_at.iso8601 end def summary Nokogiri::HTML.parse(content).inner_text.truncate(100) end def roles Role.where(name: role_visibility) end end