module ActsAsAssetable def self.included(base) base.extend ClassMethods end module ClassMethods def acts_as_assetable_on(*args) options = args.extract_options! styles = args acts_as_joinable_on :assets, :contexts => styles self.class_eval do styles.each do |k,v| name = "#{k.to_s}_image" define_method name do join_for(k) end define_method "#{name}_id" do result = join_for(k) result ? result.id : nil end define_method "#{name}=" do |asset| set_joined(k, asset) end define_method "#{name}_id=" do |id| set_joined(k, id) end end end end def acts_as_assetable(*args) acts_as_assetable_on(*args) end end end