module Humpyard::ActiveRecord::Acts::Page

Public Class Methods

included(base) click to toggle source
# File lib/humpyard/active_record/acts/page.rb, line 6
def self.included(base)
  base.has_one :page, :as => :content_data, :class_name => 'Humpyard::Page', :autosave => true
  base.validate :page_must_be_valid
  
  begin
    all_attributes = Humpyard::Page.column_names + Humpyard::Page.translated_attribute_names.map{|a| a.to_s}
  rescue
    # Table not migrated
    all_attributes = []
  end
  ignored_attributes = ['id', 'created_at', 'updated_at', 'content_data_id', 'content_data_type']
  attributes_to_delegate = all_attributes - ignored_attributes
  attributes_to_delegate.each do |attrib|
    base.delegate "#{attrib}", "#{attrib}=", "#{attrib}?", :to => :page
    if attrib.match /_id$/
      attrib = attrib.gsub /(_id)$/, ''
      base.delegate "#{attrib}", "#{attrib}=", "#{attrib}?", :to => :page
    end
  end
  
  Humpyard::Page.attr_accessible.each do |attr|
    base.attr_accessible attr
  end
  
  base.extend ClassMethods
  
  base.alias_method_chain :page, :autobuild 
  base.alias_method_chain :column_for_attribute, :page_column_for_attribute
  
end

Public Instance Methods

column_for_attribute_with_page_column_for_attribute(attr) click to toggle source
# File lib/humpyard/active_record/acts/page.rb, line 41
def column_for_attribute_with_page_column_for_attribute(attr)
  ret = column_for_attribute_without_page_column_for_attribute(attr) || Humpyard::Page.new.column_for_attribute(attr) || Humpyard::Page.translation_class.new.column_for_attribute(attr)
end
is_humpyard_dynamic_page?() click to toggle source
# File lib/humpyard/active_record/acts/page.rb, line 53
def is_humpyard_dynamic_page?
  self.class.is_humpyard_dynamic_page?
end
is_humpyard_page?() click to toggle source
# File lib/humpyard/active_record/acts/page.rb, line 49
def is_humpyard_page?
  self.class.is_humpyard_page?
end
is_humpyard_virtual_page?() click to toggle source
# File lib/humpyard/active_record/acts/page.rb, line 57
def is_humpyard_virtual_page?
  self.class.is_humpyard_virtual_page?
end
last_modified() click to toggle source

Return the logical modification time for the page, suitable for http caching, generational cache keys, etc.

# File lib/humpyard/active_record/acts/page.rb, line 62
def last_modified
  rails_root_mtime = Time.zone.at(::File.new("#{Rails.root}").mtime)
  timestamps = [rails_root_mtime, self.updated_at] + self.page.elements.collect{|e| e.last_modified}
  timestamps.sort.last
end
page_with_autobuild() click to toggle source
# File lib/humpyard/active_record/acts/page.rb, line 37
def page_with_autobuild
  page_without_autobuild || build_page
end
parse_path(path) click to toggle source
# File lib/humpyard/active_record/acts/page.rb, line 45
def parse_path(path)
  nil
end

Protected Instance Methods

page_must_be_valid() click to toggle source
# File lib/humpyard/active_record/acts/page.rb, line 83
def page_must_be_valid
  unless page.valid?
    page.errors.each do |attr, message|
      errors.add(attr, message)
    end
  end
end