Sha256: 6d6a8e35178ea44180b535720e5aa53198969c843191f8033d61a20b3e73e30d

Contents?: true

Size: 957 Bytes

Versions: 18

Compression:

Stored size: 957 Bytes

Contents

class Pulitzer::PostType < Pulitzer::ApplicationRecord
  enum kind: [ :template, :partial ]
  has_many :post_type_versions, dependent: :destroy, index_errors: true
  has_one :published_type_version, -> { where(status: 'published') }, class_name: 'PostTypeVersion'
  has_many :preview_type_versions, -> { where(status: 'prevew') }, class_name: 'PostTypeVersion'

  accepts_nested_attributes_for :post_type_versions
  
  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] }

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

  def published_type_version_id
    published_type_version&.id
  end

  def most_recent_published_post_type_version
    post_type_versions&.published&.order(version_number: :desc)&.first
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
pulitzer-0.15.31 app/models/pulitzer/post_type.rb
pulitzer-0.15.30 app/models/pulitzer/post_type.rb
pulitzer-0.15.29 app/models/pulitzer/post_type.rb
pulitzer-0.15.28 app/models/pulitzer/post_type.rb
pulitzer-0.15.27 app/models/pulitzer/post_type.rb
pulitzer-0.15.26 app/models/pulitzer/post_type.rb
pulitzer-0.15.25 app/models/pulitzer/post_type.rb
pulitzer-0.15.24 app/models/pulitzer/post_type.rb
pulitzer-0.15.23 app/models/pulitzer/post_type.rb
pulitzer-0.15.22 app/models/pulitzer/post_type.rb
pulitzer-0.15.21 app/models/pulitzer/post_type.rb
pulitzer-0.15.20 app/models/pulitzer/post_type.rb
pulitzer-0.15.19 app/models/pulitzer/post_type.rb
pulitzer-0.15.18 app/models/pulitzer/post_type.rb
pulitzer-0.15.17 app/models/pulitzer/post_type.rb
pulitzer-0.15.16 app/models/pulitzer/post_type.rb
pulitzer-0.15.14 app/models/pulitzer/post_type.rb
pulitzer-0.15.13 app/models/pulitzer/post_type.rb