lib/roachclip.rb in roachclip-0.1.3 vs lib/roachclip.rb in roachclip-0.2.0
- old
+ new
@@ -26,15 +26,27 @@
def roachclip name, options
self.attachment name
raise InvalidAttachment unless attachment_names.include?(name)
+ path = options.delete(:path) || "/gridfs/fs/%s-%s"
self.roaches << {:name => name, :options => options}
-
+
+ options[:styles] ||= {}
options[:styles].each { |k,v| self.attachment "#{name}_#{k}"}
before_save :process_roaches
before_save :destroy_nil_roaches
+
+ self.send(:define_method, "#{name}_path") do
+ (path % [self.send(name).id.to_s, Time.now.to_i]).chomp('-')
+ end
+
+ options[:styles].each do |k,v|
+ self.send(:define_method, "#{name}_#{k}_path") do
+ (path % [self.send(name).id.to_s, Time.now.to_i]).chomp('-')
+ end
+ end
end
def validates_roachclip(*args)
add_validations(args, Roachclip::Validations::ValidatesPresenceOf)
end