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
34
35
|
# File 'lib/humpyard/active_record/acts/asset.rb', line 6
def self.included(base)
base.has_one :asset, :as => :content_data, :class_name => 'Humpyard::Asset', :autosave => true
base.validate :asset_must_be_valid
begin
all_attributes = Humpyard::Asset.column_names.map{|a| a.to_s}
rescue
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 => :asset
if attrib.match /_id$/
attrib = attrib.gsub /(_id)$/, ''
base.delegate "#{attrib}", "#{attrib}=", "#{attrib}?", :to => :asset
end
end
Humpyard::Asset.attr_accessible.each do |attr|
base.attr_accessible attr
end
base.extend ClassMethods
base.alias_method_chain :asset, :autobuild
base.alias_method_chain :column_for_attribute, :asset_column_for_attribute
end
|