Sha256: 329003153d68023f1a1f2700f68f512786ce605687cb8bc8f6e5ad327e3ca76a

Contents?: true

Size: 1.08 KB

Versions: 1

Compression:

Stored size: 1.08 KB

Contents

class Pulitzer::PostType < ActiveRecord::Base
  enum kind: [ :template, :partial ]
  has_many :post_type_versions, dependent: :destroy
  has_one :published_type_version, -> { where(status: 'published') }, class_name: 'PostTypeVersion'
  has_many :preview_type_versions, -> { where(status: 'prevew') }, class_name: 'PostTypeVersion'
  has_many :posts, through: :published_type_version
  has_many :partials, through: :published_type_version
  has_many :post_type_content_element_types, through: :published_type_version
  has_many :content_element_types, through: :post_type_content_element_types
  has_many :free_form_section_types, through: :published_type_version
  has_many :layouts, through: :published_type_version

  scope :templates, -> { where(kind: Pulitzer::PostType.kinds[:template])}
  scope :partials, -> { where(kind: Pulitzer::PostType.kinds[:partial])}
  validates :name, :kind, presence: true
  validates :plural, :inclusion => { :in => [true, false] }

  def self.named(label)
    self.find_by(name: label)
  end

  def published_type_version_id
    published_type_version&.id
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pulitzer-0.15.0 app/models/pulitzer/post_type.rb