module Humpyard::ActiveRecord::Acts::Element
Public Class Methods
included(base)
click to toggle source
# File lib/humpyard/active_record/acts/element.rb 5 def self.included(base) 6 base.has_one :element, :as => :content_data, :class_name => 'Humpyard::Element', :autosave => true 7 base.validate :element_must_be_valid 8 base.alias_method_chain :element, :autobuild 9 base.alias_method_chain :column_for_attribute, :element_column_for_attribute 10 11 begin 12 all_attributes = Humpyard::Element.column_names 13 rescue 14 # Table not migrated 15 all_attributes = [] 16 end 17 ignored_attributes = ['id', 'created_at', 'updated_at', 'content_data_id', 'content_data_type'] 18 attributes_to_delegate = all_attributes - ignored_attributes 19 attributes_to_delegate.each do |attrib| 20 base.delegate "#{attrib}", "#{attrib}=", "#{attrib}?", :to => :element 21 if attrib.match /_id$/ 22 attrib = attrib.gsub /(_id)$/, '' 23 base.delegate "#{attrib}", "#{attrib}=", "#{attrib}?", :to => :element 24 end 25 end 26 27 Humpyard::Element.attr_accessible.each do |attr| 28 base.attr_accessible attr 29 end 30 31 base.extend ClassMethods 32 33 end
Public Instance Methods
column_for_attribute_with_element_column_for_attribute(attr)
click to toggle source
# File lib/humpyard/active_record/acts/element.rb 39 def column_for_attribute_with_element_column_for_attribute(attr) 40 ret = column_for_attribute_without_element_column_for_attribute(attr) || element.column_for_attribute(attr) 41 end
element_with_autobuild()
click to toggle source
# File lib/humpyard/active_record/acts/element.rb 35 def element_with_autobuild 36 element_without_autobuild || build_element 37 end
is_humpyard_container_element?()
click to toggle source
# File lib/humpyard/active_record/acts/element.rb 47 def is_humpyard_container_element? 48 self.class.is_humpyard_container_element? 49 end
is_humpyard_element?()
click to toggle source
# File lib/humpyard/active_record/acts/element.rb 43 def is_humpyard_element? 44 self.class.is_humpyard_element? 45 end
Protected Instance Methods
element_must_be_valid()
click to toggle source
# File lib/humpyard/active_record/acts/element.rb 72 def element_must_be_valid 73 unless element.valid? 74 element.errors.each do |attr, message| 75 errors.add(attr, message) 76 end 77 end 78 end