attached 0.3.5 → 0.3.6
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +4 -0
- data/lib/attached.rb +1 -1
- data/lib/attached/attachment.rb +27 -8
- data/lib/attached/storage/local.rb +3 -1
- data/lib/attached/version.rb +1 -1
- data/lib/tasks/attached.rake +1 -0
- metadata +2 -2
data/README.rdoc
CHANGED
data/lib/attached.rb
CHANGED
data/lib/attached/attachment.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'open-uri'
|
2
|
+
|
1
3
|
require 'guid'
|
2
4
|
|
3
5
|
require 'attached/storage'
|
@@ -111,13 +113,25 @@ module Attached
|
|
111
113
|
#
|
112
114
|
# Usage:
|
113
115
|
#
|
114
|
-
# @object.avatar.
|
116
|
+
# @object.avatar.attached?
|
115
117
|
|
116
|
-
def
|
118
|
+
def attached?
|
117
119
|
not identifier.blank?
|
118
120
|
end
|
119
121
|
|
120
122
|
|
123
|
+
# Custom setter for specifying an attachment.
|
124
|
+
#
|
125
|
+
# Usage:
|
126
|
+
#
|
127
|
+
# @object.avatar.file = File.open(...)
|
128
|
+
|
129
|
+
def file=(file)
|
130
|
+
@file = file
|
131
|
+
@file = file.tempfile if file.respond_to?(:tempfile)
|
132
|
+
end
|
133
|
+
|
134
|
+
|
121
135
|
# Assign an attachment to a file.
|
122
136
|
#
|
123
137
|
# Usage:
|
@@ -125,14 +139,12 @@ module Attached
|
|
125
139
|
# @object.avatar.assign(...)
|
126
140
|
|
127
141
|
def assign(file, identifier = "#{Guid.new}")
|
128
|
-
file = file
|
129
|
-
|
130
|
-
@file = file.respond_to?(:tempfile) ? file.tempfile : file
|
142
|
+
self.file = file
|
131
143
|
|
132
144
|
extension ||= File.extname(file.original_filename) if file.respond_to?(:original_filename)
|
133
145
|
extension ||= File.extname(file.path) if file.respond_to?(:path)
|
134
146
|
|
135
|
-
@purge = [self.path, *self.styles.map { |style, options| self.path(style) }] if
|
147
|
+
@purge = [self.path, *self.styles.map { |style, options| self.path(style) }] if attached?
|
136
148
|
|
137
149
|
instance_set :size, file.size
|
138
150
|
instance_set :extension, extension
|
@@ -170,7 +182,7 @@ module Attached
|
|
170
182
|
# @object.avatar.destroy
|
171
183
|
|
172
184
|
def destroy
|
173
|
-
if
|
185
|
+
if attached?
|
174
186
|
self.storage.destroy(self.path)
|
175
187
|
self.styles.each do |style, options|
|
176
188
|
self.storage.destroy(self.path(style))
|
@@ -287,9 +299,16 @@ module Attached
|
|
287
299
|
end
|
288
300
|
|
289
301
|
|
290
|
-
#
|
302
|
+
# Access the original file .
|
291
303
|
|
292
304
|
def reprocess!
|
305
|
+
uri = URI.parse(self.url)
|
306
|
+
root = "#{Rails.root}/public"
|
307
|
+
|
308
|
+
self.file ||= File.open("#{root}#{self.url}") unless uri.absolute?
|
309
|
+
self.file ||= open(uri)
|
310
|
+
|
311
|
+
process
|
293
312
|
end
|
294
313
|
|
295
314
|
|
@@ -19,7 +19,7 @@ module Attached
|
|
19
19
|
end
|
20
20
|
|
21
21
|
|
22
|
-
# Access the host (e.g.
|
22
|
+
# Access the host (e.g. /system/) for a storage service.
|
23
23
|
#
|
24
24
|
# Usage:
|
25
25
|
#
|
@@ -41,6 +41,8 @@ module Attached
|
|
41
41
|
path = "#{Rails.root}/public/system/#{path}"
|
42
42
|
dirname, basename = File.split(path)
|
43
43
|
|
44
|
+
return if file.path == path
|
45
|
+
|
44
46
|
begin
|
45
47
|
FileUtils.mkdir_p(dirname)
|
46
48
|
FileUtils.cp(file.path, path)
|
data/lib/attached/version.rb
CHANGED
data/lib/tasks/attached.rake
CHANGED
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: attached
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.3.
|
5
|
+
version: 0.3.6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Kevin Sylvestre
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-05-
|
13
|
+
date: 2011-05-25 00:00:00 -04:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|