Sha256: 5a49dd6852640e0bad365f881ea803b23f1094fbb2e8c4e3386e785cf64e9093

Contents?: true

Size: 1.46 KB

Versions: 3

Compression:

Stored size: 1.46 KB

Contents

module Pulitzer
  class Post < ActiveRecord::Base
    include ForeignOffice::Broadcaster if defined? ForeignOffice
    extend ::FriendlyId
    has_many :versions
    belongs_to :post_type
    delegate :post_type_content_element_types, :allow_free_form?, to: :post_type
    delegate :content_elements, :post_tags, :has_label_type, :has_label, :post_tags_for, to: :active_version, allow_nil: true
    friendly_id :title, use: [:slugged, :finders]
    after_create :create_preview_version

    attr_accessor :new_preview_version

    validates :title, presence: true

    TAG_MODELS = ["Pulitzer::Tag"] + Pulitzer.tagging_models

    def content_element(label)
      if content_elements
        self.content_elements.find_by(label: label)
      end
    end

    def should_generate_new_friendly_id?
      new_record? || title_changed?
    end

    def active_version
    	versions.active.last
    end

    def preview_version
    	versions.preview.last
    end

    def processing_version
      versions.processing.last
    end

    def processing_failed_version
      versions.processing_failed.last
    end

    def next_version
      preview_version || processing_version || processing_failed_version
    end

    def create_preview_version
      versions.create(status: :preview)
    end

    def create_processing_version
      versions.create(status: :processing)
    end

    def serialize
      self.attributes.merge \
        new_preview_version: self.new_preview_version
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
pulitzer-0.3.9 app/models/pulitzer/post.rb
pulitzer-0.3.8 app/models/pulitzer/post.rb
pulitzer-0.3.7 app/models/pulitzer/post.rb