lib/mongo_grid/mongoid.rb in mongo_grid-0.2.5 vs lib/mongo_grid/mongoid.rb in mongo_grid-0.2.6
- old
+ new
@@ -1,26 +1,27 @@
module ::Mongoid
module Document
- def remove_logo
- logo=self.logo
- unless logo.blank?
- id = BSON::ObjectId.from_string(logo['grid_id'])
- MongoGrid.grid.delete(id)
- end
- end
- def remove_avatar
- attach=self.avatar
+ %w[logo avatar attach].each do |name|
+ module_eval(%Q(
+ def remove_#{name}
+ attach=self.#{name}
unless attach.blank?
id = BSON::ObjectId.from_string(attach['grid_id'])
MongoGrid.grid.delete(id)
end
end
- def remove_attach
- attach=self.attach
- unless attach.blank?
- id = BSON::ObjectId.from_string(attach['grid_id'])
- MongoGrid.grid.delete(id)
- end
+ ))
end
+
+=begin
+ def self.included(base)
+ base.class_eval(%Q(
+ before_destroy :remove_logo
+ before_destroy :remove_avatar
+ before_destroy :remove_attach
+ ))
+ end
+=end
+
end
end