attached 0.3.5 → 0.3.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.rdoc CHANGED
@@ -114,6 +114,10 @@ View:
114
114
  :small => { :preset => '128kbps', :extension => '.wav' },
115
115
  }
116
116
 
117
+ === Reprocessing
118
+
119
+ rake attached:process[Image,file]
120
+
117
121
  === Aliases
118
122
 
119
123
  # app/initializer/attached.rb
data/lib/attached.rb CHANGED
@@ -73,7 +73,7 @@ module Attached
73
73
  end
74
74
 
75
75
  define_method "#{name}?" do
76
- attachment_for(name).file?
76
+ attachment_for(name).attached?
77
77
  end
78
78
 
79
79
  validates_each(name) do |record, attr, value|
@@ -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.file?
116
+ # @object.avatar.attached?
115
117
 
116
- def file?
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.file if file.is_a?(Attached::Attachment)
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 file?
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 file?
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
- # Todo.
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. https://attached.commondatastorage.googleapis.com/) for a storage service.
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)
@@ -1,3 +1,3 @@
1
1
  module Attached
2
- VERSION = "0.3.5"
2
+ VERSION = "0.3.6"
3
3
  end
@@ -10,6 +10,7 @@ namespace :attached do
10
10
 
11
11
  klass.all.each do |instance|
12
12
  instance.send(attachment).reprocess!
13
+ instance.send(attachment).save
13
14
  end
14
15
 
15
16
  end
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
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-15 00:00:00 -04:00
13
+ date: 2011-05-25 00:00:00 -04:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency