lib/roachclip.rb in roachclip-0.1.0 vs lib/roachclip.rb in roachclip-0.1.1

- old
+ new

@@ -29,11 +29,12 @@ self.roaches << {:name => name, :options => options} options[:styles].each { |k,v| self.attachment "#{name}_#{k}"} - before_save :process_roaches + before_save :process_roaches + before_save :destroy_nil_roaches end end module InstanceMethods def process_roaches @@ -53,9 +54,22 @@ thumbnail = Paperclip::Thumbnail.new src, styles[style_key] tmp_file_name = thumbnail.make stored_file_name = send("#{name}_name").gsub(/\.(\w*)\Z/) { "_#{style_key}.#{$1}" } send "#{name}_#{style_key}=", tmp_file_name send "#{name}_#{style_key}_name=", stored_file_name + end + end + end + + def destroy_nil_roaches + roaches.each do |img| + name = img[:name] + styles = img[:options][:styles] + + return unless @nil_attachments && @nil_attachments.include?(name) + + styles.keys.each do |style_key| + send "#{name}_#{style_key}=", nil end end end end end