Sha256: 91831df64ee6c9e9f8d370a3dd426f2cd663098936d78e209b58aaa611d48d83

Contents?: true

Size: 986 Bytes

Versions: 25

Compression:

Stored size: 986 Bytes

Contents

class Pulitzer::PostType < ActiveRecord::Base
  enum kind: [ :template, :partial ]
  has_many :posts, dependent: :destroy
  has_many :partials, dependent: :destroy
  has_many :post_type_content_element_types, dependent: :destroy
  has_many :content_element_types, through: :post_type_content_element_types
  has_many :free_form_section_types, dependent: :destroy
  has_many :layouts, dependent: :destroy

  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 singular?
    !plural
  end

  def singleton_post
    posts.first
  end

  def singleton_post?
    !plural
  end

  def has_templated_content_elements?
    content_element_types.any?
  end

  def has_free_form_sections?
    free_form_section_types.any?
  end

end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
pulitzer-0.5.1 app/models/pulitzer/post_type.rb
pulitzer-0.4.16 app/models/pulitzer/post_type.rb
pulitzer-0.4.15 app/models/pulitzer/post_type.rb
pulitzer-0.4.14 app/models/pulitzer/post_type.rb
pulitzer-0.4.13 app/models/pulitzer/post_type.rb