cached_uploads 0.0.0 → 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/cached_uploads.rb +15 -8
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 25eb30d198519ca87aee08ab105fee301f416b2f
|
4
|
+
data.tar.gz: d6fbb61e52061258e47f66da6871c062e8aa4c46
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2cfd124c60fe3e437964b38b9309f7a6b12a444e84359aca3bc3c4fb647b71d339dedd382a34551f5109a8c5c8abeb65726197ca6a39f8caa062567332587c7d
|
7
|
+
data.tar.gz: 3be31bebf1099ba241b2c57dbeb48504725dd415b5be4c9666c367916eb02f58f2dc2404bd1738a38d203dc18ec590968a050c7e1daa96ae1433ae5d5eb2cec9
|
data/lib/cached_uploads.rb
CHANGED
@@ -122,7 +122,7 @@ module CachedUploads
|
|
122
122
|
# example, instead of explicitly defining a #screenshot_path method, you can do this:
|
123
123
|
#
|
124
124
|
# has_cached_upload(:screenshot, {
|
125
|
-
# folder: ->() { File.join Rails.root, 'uploads/screenshots' }
|
125
|
+
# folder: ->() { File.join Rails.root, 'uploads/screenshots' },
|
126
126
|
# filename: ->(obj) { "#{obj.id}.png" }
|
127
127
|
# })
|
128
128
|
#
|
@@ -164,6 +164,11 @@ module CachedUploads
|
|
164
164
|
#
|
165
165
|
# - +md5_attr+: Name of the instance attribute storing the file's MD5 hash. Defaults
|
166
166
|
# to +"tmp_#{file_attr}_md5"+.
|
167
|
+
#
|
168
|
+
# - +no_prm:+ If set to true, permanent files won't be written to disk. You might
|
169
|
+
# want to use this if, for example, you're hosting uploaded files on an external
|
170
|
+
# CDN. Options related to the permanent file have no effect when this option is
|
171
|
+
# true.
|
167
172
|
def has_cached_upload(file_attr, options = {})
|
168
173
|
# Set default configs.
|
169
174
|
options.reverse_merge!(
|
@@ -225,14 +230,16 @@ module CachedUploads
|
|
225
230
|
end
|
226
231
|
end
|
227
232
|
|
228
|
-
|
229
|
-
|
230
|
-
obj
|
231
|
-
|
233
|
+
unless options[:no_prm]
|
234
|
+
# Register the save callback.
|
235
|
+
after_save do |obj|
|
236
|
+
obj.write_permanent_file file_attr
|
237
|
+
end
|
232
238
|
|
233
|
-
|
234
|
-
|
235
|
-
|
239
|
+
# Register the delete callback.
|
240
|
+
after_destroy do |obj|
|
241
|
+
obj.delete_permanent_file file_attr
|
242
|
+
end
|
236
243
|
end
|
237
244
|
end
|
238
245
|
end
|