attached 0.2.4 → 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +4 -4
- data/lib/attached/attachment.rb +33 -9
- data/lib/attached/version.rb +1 -1
- metadata +4 -16
data/README.rdoc
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
= Attached
|
2
2
|
|
3
|
-
Attached is a Ruby on Rails file attachment tool that lets users upload to the cloud
|
3
|
+
Attached is a Ruby on Rails file attachment tool that lets users upload to the cloud. The gem supports AWS, Google and Rackspace for storage networks by default. It is influenced (and copied) from Paperclip and uses the incredibly awesome Fog library in the back.
|
4
4
|
|
5
5
|
== Requirements
|
6
6
|
|
@@ -70,10 +70,10 @@ View:
|
|
70
70
|
has_attached :avatar, :medium => :aws, :credentials => "#{Rails.root}/config/aws.yml"
|
71
71
|
|
72
72
|
# app/models/person.rb
|
73
|
-
has_attached :avatar, :medium => :google, "#{Rails.root}/config/google.yml"
|
73
|
+
has_attached :avatar, :medium => :google, :credentials => "#{Rails.root}/config/google.yml"
|
74
74
|
|
75
75
|
# app/models/person.rb
|
76
|
-
has_attached :avatar, :medium => :rackspace, "#{Rails.root}/config/rackspace.yml"
|
76
|
+
has_attached :avatar, :medium => :rackspace, :credentials => "#{Rails.root}/config/rackspace.yml"
|
77
77
|
|
78
78
|
# config/initializers/attached.rb
|
79
79
|
Attached::Attachment.options[:medium] = :aws
|
@@ -99,7 +99,7 @@ View:
|
|
99
99
|
=== Aliases
|
100
100
|
|
101
101
|
# app/initializer/attached.rb
|
102
|
-
Attached::Attachment.options[:alias] = http://c0378198.cdn2.cloudfiles.rackspacecloud.com
|
102
|
+
Attached::Attachment.options[:alias] = http://c0378198.cdn2.cloudfiles.rackspacecloud.com/
|
103
103
|
|
104
104
|
# app/initializer/attached.rb
|
105
105
|
Attached::Attachment.options[:aliases] = %w(
|
data/lib/attached/attachment.rb
CHANGED
@@ -15,6 +15,7 @@ module Attached
|
|
15
15
|
attr_reader :name
|
16
16
|
attr_reader :instance
|
17
17
|
attr_reader :queue
|
18
|
+
attr_reader :purge
|
18
19
|
attr_reader :errors
|
19
20
|
attr_reader :path
|
20
21
|
attr_reader :styles
|
@@ -58,9 +59,13 @@ module Attached
|
|
58
59
|
# Options:
|
59
60
|
#
|
60
61
|
# * :path - The location where the attachment is stored
|
61
|
-
# * :storage - The storage medium represented as a symbol such as ':s3'
|
62
|
-
# * :credentials - A file, hash, or path used to authenticate with the specified storage medium
|
63
62
|
# * :styles - A hash containing optional parameters including extension and identifier
|
63
|
+
# * :credentials - A file, hash, or path used to authenticate with the specified storage medium
|
64
|
+
# * :medium - A symbol or subclass of 'Attached::Storage::Base' to be used
|
65
|
+
# * :processor - A symbol or subclass of 'Attached::Processor::Base' to be used
|
66
|
+
# * :alias - A string representing a fully qualified host alias
|
67
|
+
# * :processors - An array of processors
|
68
|
+
# * :aliases - An array of aliases
|
64
69
|
|
65
70
|
def initialize(name, instance, options = {})
|
66
71
|
options = self.class.options.merge(options)
|
@@ -68,8 +73,9 @@ module Attached
|
|
68
73
|
@name = name
|
69
74
|
@instance = instance
|
70
75
|
|
71
|
-
@queue
|
72
|
-
@
|
76
|
+
@queue = {}
|
77
|
+
@purge = []
|
78
|
+
@errors = []
|
73
79
|
|
74
80
|
@path = options[:path]
|
75
81
|
@styles = options[:styles]
|
@@ -111,12 +117,14 @@ module Attached
|
|
111
117
|
#
|
112
118
|
# @object.avatar.assign(...)
|
113
119
|
|
114
|
-
def assign(file, identifier = Guid.new)
|
120
|
+
def assign(file, identifier = "#{Guid.new}")
|
115
121
|
@file = file.respond_to?(:tempfile) ? file.tempfile : file
|
116
122
|
|
117
123
|
extension ||= File.extname(file.original_filename) if file.respond_to?(:original_filename)
|
118
124
|
extension ||= File.extname(file.path) if file.respond_to?(:path)
|
119
|
-
|
125
|
+
|
126
|
+
@purge = [self.path, *self.styles.map { |style, options| self.path(style) }] if file?
|
127
|
+
|
120
128
|
instance_set :size, file.size
|
121
129
|
instance_set :extension, extension
|
122
130
|
instance_set :identifier, identifier
|
@@ -132,10 +140,16 @@ module Attached
|
|
132
140
|
# @object.avatar.save
|
133
141
|
|
134
142
|
def save
|
135
|
-
|
136
|
-
|
143
|
+
self.purge.each do |path|
|
144
|
+
self.storage.destroy(path)
|
145
|
+
end
|
146
|
+
|
147
|
+
self.queue.each do |style, file|
|
148
|
+
path = self.path(style)
|
149
|
+
self.storage.save(file, path) if file and path
|
137
150
|
end
|
138
151
|
|
152
|
+
@purge = []
|
139
153
|
@queue = {}
|
140
154
|
end
|
141
155
|
|
@@ -147,7 +161,15 @@ module Attached
|
|
147
161
|
# @object.avatar.destroy
|
148
162
|
|
149
163
|
def destroy
|
150
|
-
|
164
|
+
if file?
|
165
|
+
self.storage.destroy(self.path)
|
166
|
+
self.styles.each do |style, options|
|
167
|
+
self.storage.destroy(self.path(style))
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
@purge = []
|
172
|
+
@queue = {}
|
151
173
|
end
|
152
174
|
|
153
175
|
|
@@ -243,6 +265,7 @@ module Attached
|
|
243
265
|
instance_set(:extension, extension)
|
244
266
|
end
|
245
267
|
|
268
|
+
|
246
269
|
# Set the identifier for an attachment. It will act independently of the
|
247
270
|
# defined style.
|
248
271
|
#
|
@@ -262,6 +285,7 @@ module Attached
|
|
262
285
|
|
263
286
|
|
264
287
|
private
|
288
|
+
|
265
289
|
|
266
290
|
# Helper function for calling processors (will queue default).
|
267
291
|
#
|
data/lib/attached/version.rb
CHANGED
metadata
CHANGED
@@ -1,12 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: attached
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
prerelease:
|
5
|
-
|
6
|
-
- 0
|
7
|
-
- 2
|
8
|
-
- 4
|
9
|
-
version: 0.2.4
|
4
|
+
prerelease:
|
5
|
+
version: 0.2.5
|
10
6
|
platform: ruby
|
11
7
|
authors:
|
12
8
|
- Kevin Sylvestre
|
@@ -14,7 +10,7 @@ autorequire:
|
|
14
10
|
bindir: bin
|
15
11
|
cert_chain: []
|
16
12
|
|
17
|
-
date: 2011-
|
13
|
+
date: 2011-02-12 00:00:00 -05:00
|
18
14
|
default_executable:
|
19
15
|
dependencies:
|
20
16
|
- !ruby/object:Gem::Dependency
|
@@ -25,8 +21,6 @@ dependencies:
|
|
25
21
|
requirements:
|
26
22
|
- - ">="
|
27
23
|
- !ruby/object:Gem::Version
|
28
|
-
segments:
|
29
|
-
- 0
|
30
24
|
version: "0"
|
31
25
|
type: :runtime
|
32
26
|
version_requirements: *id001
|
@@ -38,8 +32,6 @@ dependencies:
|
|
38
32
|
requirements:
|
39
33
|
- - ">="
|
40
34
|
- !ruby/object:Gem::Version
|
41
|
-
segments:
|
42
|
-
- 0
|
43
35
|
version: "0"
|
44
36
|
type: :runtime
|
45
37
|
version_requirements: *id002
|
@@ -87,21 +79,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
87
79
|
requirements:
|
88
80
|
- - ">="
|
89
81
|
- !ruby/object:Gem::Version
|
90
|
-
segments:
|
91
|
-
- 0
|
92
82
|
version: "0"
|
93
83
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
94
84
|
none: false
|
95
85
|
requirements:
|
96
86
|
- - ">="
|
97
87
|
- !ruby/object:Gem::Version
|
98
|
-
segments:
|
99
|
-
- 0
|
100
88
|
version: "0"
|
101
89
|
requirements: []
|
102
90
|
|
103
91
|
rubyforge_project:
|
104
|
-
rubygems_version: 1.
|
92
|
+
rubygems_version: 1.5.0
|
105
93
|
signing_key:
|
106
94
|
specification_version: 3
|
107
95
|
summary: An attachment library designed with cloud processors in mind
|