module Humpyard::ActiveRecord::Acts::Page

Public Class Methods

included(base) click to toggle source
   # File lib/humpyard/active_record/acts/page.rb
 6 def self.included(base)
 7   base.has_one :page, :as => :content_data, :class_name => 'Humpyard::Page', :autosave => true
 8   base.validate :page_must_be_valid
 9   
10   begin
11     all_attributes = Humpyard::Page.column_names + Humpyard::Page.translated_attribute_names.map{|a| a.to_s}
12   rescue
13     # Table not migrated
14     all_attributes = []
15   end
16   ignored_attributes = ['id', 'created_at', 'updated_at', 'content_data_id', 'content_data_type']
17   attributes_to_delegate = all_attributes - ignored_attributes
18   attributes_to_delegate.each do |attrib|
19     base.delegate "#{attrib}", "#{attrib}=", "#{attrib}?", :to => :page
20     if attrib.match /_id$/
21       attrib = attrib.gsub /(_id)$/, ''
22       base.delegate "#{attrib}", "#{attrib}=", "#{attrib}?", :to => :page
23     end
24   end
25   
26   Humpyard::Page.attr_accessible.each do |attr|
27     base.attr_accessible attr
28   end
29   
30   base.extend ClassMethods
31   
32   base.alias_method_chain :page, :autobuild 
33   base.alias_method_chain :column_for_attribute, :page_column_for_attribute
34   
35 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
41 def column_for_attribute_with_page_column_for_attribute(attr)
42   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)
43 end
is_humpyard_dynamic_page?() click to toggle source
   # File lib/humpyard/active_record/acts/page.rb
53 def is_humpyard_dynamic_page?
54   self.class.is_humpyard_dynamic_page?
55 end
is_humpyard_page?() click to toggle source
   # File lib/humpyard/active_record/acts/page.rb
49 def is_humpyard_page?
50   self.class.is_humpyard_page?
51 end
is_humpyard_virtual_page?() click to toggle source
   # File lib/humpyard/active_record/acts/page.rb
57 def is_humpyard_virtual_page?
58   self.class.is_humpyard_virtual_page?
59 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
62 def last_modified
63   rails_root_mtime = Time.zone.at(::File.new("#{Rails.root}").mtime)
64   timestamps = [rails_root_mtime, self.updated_at] + self.page.elements.collect{|e| e.last_modified}
65   timestamps.sort.last
66 end
page_with_autobuild() click to toggle source
   # File lib/humpyard/active_record/acts/page.rb
37 def page_with_autobuild
38   page_without_autobuild || build_page
39 end
parse_path(path) click to toggle source
   # File lib/humpyard/active_record/acts/page.rb
45 def parse_path(path)
46   nil
47 end

Protected Instance Methods

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