Sha256: c5bb7b4a608151adeada323020aee3404fbacff396a172915331675bed52f598

Contents?: true

Size: 1.97 KB

Versions: 2

Compression:

Stored size: 1.97 KB

Contents

require_dependency 'landable/has_assets'

module Landable
  class PageRevision < ActiveRecord::Base
    include Landable::Engine.routes.url_helpers
    include Landable::HasAssets
    include Landable::TableName

    @@ignored_page_attributes = [
      'page_id',
      'imported_at',
      'created_at',
      'updated_at',
      'published_revision_id',
      'is_publishable',
      'updated_by_author_id',
      'lock_version'
    ]

    cattr_accessor :ignored_page_attributes

    belongs_to :author
    belongs_to :page, inverse_of: :revisions
    has_many   :screenshots, class_name: 'Landable::Screenshot', as: :screenshotable

    def page_id=(id)
      # set the value
      self[:page_id] = id

      # copy grab attributes from the page
      self.title          = page.title
      self.body           = page.body
      self.head_content   = page.head_content
      self.path           = page.path
      self.status_code    = page.status_code
      self.category_id    = page.category_id
      self.theme_id       = page.theme_id
      self.meta_tags      = page.meta_tags
      self.redirect_url   = page.redirect_url
      self.abstract       = page.abstract
      self.hero_asset_id  = page.hero_asset_id
    end

    def snapshot
      Page.new(title: self.title, 
               meta_tags: page.meta_tags, 
               head_content: page.head_content,
               body: self.body, 
               path: self.path, 
               redirect_url: self.redirect_url, 
               status_code: self.status_code, 
               theme_id: self.theme_id, 
               category_id: self.category_id,
               abstract: self.abstract,
               hero_asset_id: self.hero_asset_id)
    end

    def publish!
      update_attribute :is_published, true
    end

    def unpublish!
      update_attribute :is_published, false
    end

    def preview_url
      public_preview_page_revision_url(self)
    end

    def preview_path
      public_preview_page_revision_path(self)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
landable-1.7.1.rc1 app/models/landable/page_revision.rb
landable-1.7.0 app/models/landable/page_revision.rb