Module: FileDelete::ClassMethods
- Defined in:
- lib/paperclip_delete_helpers.rb
Instance Method Summary collapse
- #find_del_files ⇒ Object
- #find_deletable_files(models) ⇒ Object
- #has_deletable_file(name, options = {}) ⇒ Object
Instance Method Details
#find_del_files ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/paperclip_delete_helpers.rb', line 30 def find_del_files = self.read_inheritable_attribute(:attachment_definitions) .each do | | puts "calling HDF for #{self} using #{.first}\n" self.send(:has_deletable_file, .first) end end |
#find_deletable_files(models) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/paperclip_delete_helpers.rb', line 38 def find_deletable_files(models) models.each do |model| = model.read_inheritable_attribute(:attachment_definitions) .each do | | puts "calling HDF for #{model} using #{.first}\n" model.send(:has_deletable_file, .first) end end end |
#has_deletable_file(name, options = {}) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/paperclip_delete_helpers.rb', line 50 def has_deletable_file name, ={} 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 |