Sha256: 6c15e4843267ae2df4fe89359b3038c8e7ad0bba5e89004a6d0d5aa53613e864
Contents?: true
Size: 1.2 KB
Versions: 3
Compression:
Stored size: 1.2 KB
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 def all_element_types (post_type_content_element_types.to_a + free_form_section_types.to_a) end def highest_element_sort last_element = all_element_types.max_by{ |e| e.sort_order || 0} last_element&.sort_order || 0 end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
pulitzer-0.12.4 | app/models/pulitzer/post_type.rb |
pulitzer-0.12.3 | app/models/pulitzer/post_type.rb |
pulitzer-0.12.2 | app/models/pulitzer/post_type.rb |