attached 0.4.1 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +8 -3
- data/lib/attached.rb +1 -0
- data/lib/attached/attachment.rb +52 -14
- data/lib/attached/job.rb +20 -0
- data/lib/attached/version.rb +1 -1
- metadata +42 -45
data/README.rdoc
CHANGED
@@ -4,7 +4,7 @@ Attached is a Ruby on Rails file attachment tool that lets users upload to the c
|
|
4
4
|
|
5
5
|
== Requirements
|
6
6
|
|
7
|
-
The gem is tested with Ruby 1.9.2 and Rails 3.0.
|
7
|
+
The gem is tested with Ruby 1.9.2 and Rails 3.0.9 but may well work with other versions of Ruby and Rails.
|
8
8
|
|
9
9
|
== Installation
|
10
10
|
|
@@ -98,7 +98,7 @@ View:
|
|
98
98
|
Attached::Attachment.options[:medium] = :rackspace
|
99
99
|
Attached::Attachment.options[:credentials] = "#{Rails.root}/config/rackspace.yml"
|
100
100
|
|
101
|
-
===
|
101
|
+
=== Processors
|
102
102
|
|
103
103
|
# app/models/image.rb
|
104
104
|
has_attached :file, processor: :image, styles: {
|
@@ -135,11 +135,16 @@ View:
|
|
135
135
|
small: { preset: 'medium', extension: '.wav' },
|
136
136
|
}
|
137
137
|
|
138
|
-
|
138
|
+
=== Strategies
|
139
|
+
|
140
|
+
# app/models/sample.rb
|
141
|
+
has_attached :file, processor: ..., styles: { ... }, strategy: :delay
|
142
|
+
has_attached :file, processor: ..., styles: { ... }, strategy: :cache
|
139
143
|
|
140
144
|
=== Reprocessing
|
141
145
|
|
142
146
|
rake attached:process[Image,file]
|
147
|
+
rake attached:process[Audio,file]
|
143
148
|
|
144
149
|
=== Aliases
|
145
150
|
|
data/lib/attached.rb
CHANGED
data/lib/attached/attachment.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
1
|
+
require 'identifier'
|
2
2
|
|
3
3
|
require 'attached/storage'
|
4
4
|
require 'attached/storage/error'
|
@@ -21,6 +21,7 @@ module Attached
|
|
21
21
|
attr_reader :missing
|
22
22
|
attr_reader :styles
|
23
23
|
attr_reader :default
|
24
|
+
attr_reader :strategy
|
24
25
|
attr_reader :medium
|
25
26
|
attr_reader :credentials
|
26
27
|
attr_reader :processors
|
@@ -44,9 +45,6 @@ module Attached
|
|
44
45
|
:default => :original,
|
45
46
|
:medium => :local,
|
46
47
|
:credentials => {},
|
47
|
-
:styles => {},
|
48
|
-
:processors => [],
|
49
|
-
:aliases => [],
|
50
48
|
}
|
51
49
|
end
|
52
50
|
|
@@ -70,7 +68,11 @@ module Attached
|
|
70
68
|
# * :aliases - An array of aliases
|
71
69
|
|
72
70
|
def initialize(name, instance, options = {})
|
73
|
-
options = self.class.options.merge(options)
|
71
|
+
options = self.class.options.clone.merge(options)
|
72
|
+
|
73
|
+
options[:styles] ||= {}
|
74
|
+
options[:aliases] ||= []
|
75
|
+
options[:processors] ||= []
|
74
76
|
|
75
77
|
@name = name
|
76
78
|
@instance = instance
|
@@ -83,6 +85,7 @@ module Attached
|
|
83
85
|
@missing = options[:missing]
|
84
86
|
@styles = options[:styles]
|
85
87
|
@default = options[:default]
|
88
|
+
@strategy = options[:strategy]
|
86
89
|
@medium = options[:medium]
|
87
90
|
@credentials = options[:credentials]
|
88
91
|
@processors = options[:processors]
|
@@ -90,8 +93,8 @@ module Attached
|
|
90
93
|
@aliases = options[:aliases]
|
91
94
|
@alias = options[:alias]
|
92
95
|
|
93
|
-
@
|
94
|
-
@
|
96
|
+
@aliases = self.aliases << self.alias if self.alias
|
97
|
+
@processors = self.processors << self.processor if self.processor
|
95
98
|
|
96
99
|
@storage = Attached::Storage.storage(self.medium, self.credentials)
|
97
100
|
|
@@ -150,19 +153,21 @@ module Attached
|
|
150
153
|
#
|
151
154
|
# @object.avatar.assign(...)
|
152
155
|
|
153
|
-
def assign(file, identifier =
|
156
|
+
def assign(file, identifier = Identifier.generate)
|
154
157
|
self.file = file
|
155
158
|
|
156
|
-
|
157
|
-
|
159
|
+
if file
|
160
|
+
extension ||= File.extname(file.original_filename) if file.respond_to?(:original_filename)
|
161
|
+
extension ||= File.extname(file.path) if file.respond_to?(:path)
|
162
|
+
end
|
158
163
|
|
159
164
|
@purge = [self.path, *self.styles.map { |style, options| self.path(style) }] if attached?
|
160
165
|
|
161
|
-
|
162
|
-
|
163
|
-
|
166
|
+
self.size = file ? file.size : nil
|
167
|
+
self.extension = file ? extension : nil
|
168
|
+
self.identifier = file ? identifier : nil
|
164
169
|
|
165
|
-
process
|
170
|
+
process if file
|
166
171
|
end
|
167
172
|
|
168
173
|
|
@@ -255,6 +260,17 @@ module Attached
|
|
255
260
|
end
|
256
261
|
|
257
262
|
|
263
|
+
# Access the status for an attachment.
|
264
|
+
#
|
265
|
+
# Usage:
|
266
|
+
#
|
267
|
+
# @object.avatar.status
|
268
|
+
|
269
|
+
def status
|
270
|
+
instance_get(:status)
|
271
|
+
end
|
272
|
+
|
273
|
+
|
258
274
|
# Access the extension for an attachment. It will first check the styles
|
259
275
|
# to see if one is specified before checking the instance.
|
260
276
|
#
|
@@ -287,6 +303,28 @@ module Attached
|
|
287
303
|
end
|
288
304
|
|
289
305
|
|
306
|
+
# Set the size for an attachment.
|
307
|
+
#
|
308
|
+
# Usage:
|
309
|
+
#
|
310
|
+
# @object.avatar.size = 1024
|
311
|
+
|
312
|
+
def size=(size)
|
313
|
+
instance_set(:size, size)
|
314
|
+
end
|
315
|
+
|
316
|
+
|
317
|
+
# Set the status for an attachment.
|
318
|
+
#
|
319
|
+
# Usage:
|
320
|
+
#
|
321
|
+
# @object.avatar.status = 'processing'
|
322
|
+
|
323
|
+
def status=(status)
|
324
|
+
instance_set(:size, status)
|
325
|
+
end
|
326
|
+
|
327
|
+
|
290
328
|
# Set the extension for an attachment. It will act independently of the
|
291
329
|
# defined style.
|
292
330
|
#
|
data/lib/attached/job.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
module Attached
|
2
|
+
class Job
|
3
|
+
@queue = :attached
|
4
|
+
|
5
|
+
def self.perform(klass, id, method)
|
6
|
+
object = eval(klass).find(id)
|
7
|
+
attachment = object.send(name)
|
8
|
+
attachment.reprocess!
|
9
|
+
attachment.status = 'active'
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.enqueue(attachment)
|
13
|
+
klass = attachment.instance.class.name
|
14
|
+
id = attachment.instance.id
|
15
|
+
method = attachment.name
|
16
|
+
attachment.status = 'processing'
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
data/lib/attached/version.rb
CHANGED
metadata
CHANGED
@@ -1,50 +1,50 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: attached
|
3
|
-
version: !ruby/object:Gem::Version
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.4.2
|
4
5
|
prerelease:
|
5
|
-
version: 0.4.1
|
6
6
|
platform: ruby
|
7
|
-
authors:
|
7
|
+
authors:
|
8
8
|
- Kevin Sylvestre
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
dependencies:
|
15
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2011-07-24 00:00:00.000000000 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
16
|
name: fog
|
17
|
-
|
18
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
17
|
+
requirement: &70341108747620 !ruby/object:Gem::Requirement
|
19
18
|
none: false
|
20
|
-
requirements:
|
21
|
-
- -
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version:
|
19
|
+
requirements:
|
20
|
+
- - ! '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '0'
|
24
23
|
type: :runtime
|
25
|
-
version_requirements: *id001
|
26
|
-
- !ruby/object:Gem::Dependency
|
27
|
-
name: guid
|
28
24
|
prerelease: false
|
29
|
-
|
25
|
+
version_requirements: *70341108747620
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: identifier
|
28
|
+
requirement: &70341108747060 !ruby/object:Gem::Requirement
|
30
29
|
none: false
|
31
|
-
requirements:
|
32
|
-
- -
|
33
|
-
- !ruby/object:Gem::Version
|
34
|
-
version:
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
35
34
|
type: :runtime
|
36
|
-
|
37
|
-
|
38
|
-
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: *70341108747060
|
37
|
+
description: Attached is a Ruby on Rails cloud attachment and processor library inspired
|
38
|
+
by Paperclip. Attached lets users push files to the cloud, then perform remote processing
|
39
|
+
on the files.
|
40
|
+
email:
|
39
41
|
- kevin@ksylvest.com
|
40
42
|
executables: []
|
41
|
-
|
42
43
|
extensions: []
|
43
|
-
|
44
44
|
extra_rdoc_files: []
|
45
|
-
|
46
|
-
files:
|
45
|
+
files:
|
47
46
|
- lib/attached/attachment.rb
|
47
|
+
- lib/attached/job.rb
|
48
48
|
- lib/attached/processor/audio.rb
|
49
49
|
- lib/attached/processor/base.rb
|
50
50
|
- lib/attached/processor/error.rb
|
@@ -65,32 +65,29 @@ files:
|
|
65
65
|
- LICENSE
|
66
66
|
- Gemfile
|
67
67
|
- Rakefile
|
68
|
+
has_rdoc: true
|
68
69
|
homepage: http://github.com/ksylvest/attached
|
69
70
|
licenses: []
|
70
|
-
|
71
71
|
post_install_message:
|
72
72
|
rdoc_options: []
|
73
|
-
|
74
|
-
require_paths:
|
73
|
+
require_paths:
|
75
74
|
- lib
|
76
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
75
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
77
76
|
none: false
|
78
|
-
requirements:
|
79
|
-
- -
|
80
|
-
- !ruby/object:Gem::Version
|
81
|
-
version:
|
82
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - ! '>='
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
81
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
83
82
|
none: false
|
84
|
-
requirements:
|
85
|
-
- -
|
86
|
-
- !ruby/object:Gem::Version
|
87
|
-
version:
|
83
|
+
requirements:
|
84
|
+
- - ! '>='
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
88
87
|
requirements: []
|
89
|
-
|
90
88
|
rubyforge_project:
|
91
|
-
rubygems_version: 1.
|
89
|
+
rubygems_version: 1.6.2
|
92
90
|
signing_key:
|
93
91
|
specification_version: 3
|
94
92
|
summary: An attachment library designed with cloud processors in mind
|
95
93
|
test_files: []
|
96
|
-
|