Module: Humpyard::ActiveRecord::Acts::Element
- Defined in:
- lib/humpyard/active_record/acts/element.rb
Defined Under Namespace
Modules: ClassMethods, InstanceMethods
Class Method Summary collapse
Instance Method Summary collapse
- #column_for_attribute_with_element_column_for_attribute(attr) ⇒ Object
- #element_with_autobuild ⇒ Object
- #is_humpyard_container_element? ⇒ Boolean
- #is_humpyard_element? ⇒ Boolean
Class Method Details
.included(base) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/humpyard/active_record/acts/element.rb', line 5 def self.included(base) base.has_one :element, :as => :content_data, :class_name => 'Humpyard::Element', :autosave => true base.validate :element_must_be_valid base.alias_method_chain :element, :autobuild base.alias_method_chain :column_for_attribute, :element_column_for_attribute begin all_attributes = Humpyard::Element.column_names 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 => :element if attrib.match /_id$/ attrib = attrib.gsub /(_id)$/, '' base.delegate "#{attrib}", "#{attrib}=", "#{attrib}?", :to => :element end end Humpyard::Element.attr_accessible.each do |attr| base.attr_accessible attr end base.extend ClassMethods end |
Instance Method Details
#column_for_attribute_with_element_column_for_attribute(attr) ⇒ Object
39 40 41 |
# File 'lib/humpyard/active_record/acts/element.rb', line 39 def column_for_attribute_with_element_column_for_attribute(attr) ret = column_for_attribute_without_element_column_for_attribute(attr) || element.column_for_attribute(attr) end |
#element_with_autobuild ⇒ Object
35 36 37 |
# File 'lib/humpyard/active_record/acts/element.rb', line 35 def element_with_autobuild element_without_autobuild || build_element end |
#is_humpyard_container_element? ⇒ Boolean
47 48 49 |
# File 'lib/humpyard/active_record/acts/element.rb', line 47 def is_humpyard_container_element? self.class.is_humpyard_container_element? end |
#is_humpyard_element? ⇒ Boolean
43 44 45 |
# File 'lib/humpyard/active_record/acts/element.rb', line 43 def is_humpyard_element? self.class.is_humpyard_element? end |