module Humpyard::ActiveRecord::Acts::Asset
Public Class Methods
included(base)
click to toggle source
# File lib/humpyard/active_record/acts/asset.rb 6 def self.included(base) 7 base.has_one :asset, :as => :content_data, :class_name => 'Humpyard::Asset', :autosave => true 8 base.validate :asset_must_be_valid 9 10 begin 11 all_attributes = Humpyard::Asset.column_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 => :asset 20 if attrib.match /_id$/ 21 attrib = attrib.gsub /(_id)$/, '' 22 base.delegate "#{attrib}", "#{attrib}=", "#{attrib}?", :to => :asset 23 end 24 end 25 26 Humpyard::Asset.attr_accessible.each do |attr| 27 base.attr_accessible attr 28 end 29 30 base.extend ClassMethods 31 32 base.alias_method_chain :asset, :autobuild 33 base.alias_method_chain :column_for_attribute, :asset_column_for_attribute 34 35 end
Public Instance Methods
asset_with_autobuild()
click to toggle source
# File lib/humpyard/active_record/acts/asset.rb 37 def asset_with_autobuild 38 asset_without_autobuild || build_asset 39 end
column_for_attribute_with_asset_column_for_attribute(attr)
click to toggle source
# File lib/humpyard/active_record/acts/asset.rb 41 def column_for_attribute_with_asset_column_for_attribute(attr) 42 ret = column_for_attribute_without_asset_column_for_attribute(attr) || Humpyard::Asset.new.column_for_attribute(attr) 43 end
Protected Instance Methods
asset_must_be_valid()
click to toggle source
# File lib/humpyard/active_record/acts/asset.rb 50 def asset_must_be_valid 51 unless asset.valid? 52 asset.errors.each do |attr, message| 53 errors.add(attr, message) 54 end 55 end 56 end