module FileDelete::ClassMethods

Public Instance Methods

find_del_files() click to toggle source
# File lib/paperclip_delete_helpers.rb, line 30
def find_del_files
  attachments = self.read_inheritable_attribute(:attachment_definitions)
  attachments.each do | attachment |
    puts "calling HDF for #{self} using #{attachment.first}\n"
    self.send(:has_deletable_file, attachment.first)
  end
end
find_deletable_files(models) click to toggle source
# File lib/paperclip_delete_helpers.rb, line 38
def find_deletable_files(models)
  
  models.each do |model|
    attachments = model.read_inheritable_attribute(:attachment_definitions)
    attachments.each do | attachment |
      puts "calling HDF for #{model} using #{attachment.first}\n"
      model.send(:has_deletable_file, attachment.first)
    end
  end
  
end
has_deletable_file(name, options ={}) click to toggle source
# File lib/paperclip_delete_helpers.rb, line 50
def has_deletable_file name, options ={}
  
  before_validation "check_delete_#{name}".to_sym
        
  define_method "delete_#{name}=" do |value|
    self.instance_variable_set("@delete_#{name}".to_sym, !value.to_i.zero?)
    
  end
  
  define_method "delete_#{name}" do
    !!self.instance_variable_get("@delete_#{name}".to_sym)
    
  end
  
  alias_method "delete_#{name}?".to_sym, "delete_#{name}".to_sym
  
  define_method "check_delete_#{name}" do
     self.send(name).send(:destroy) if self.send("delete_#{name}?".to_sym) and !self.send(name).send(:dirty?)
  end
   
end