attached 0.3.2 → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +20 -14
- data/lib/attached.rb +13 -0
- data/lib/attached/attachment.rb +4 -7
- data/lib/attached/railtie.rb +1 -1
- data/lib/attached/version.rb +1 -1
- metadata +3 -3
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. The gem supports AWS, Google and Rackspace for storage networks by default. It is influenced (and copied) from Paperclip and
|
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 makes heavy use of the incredibly awesome Fog library.
|
4
4
|
|
5
5
|
== Requirements
|
6
6
|
|
@@ -14,12 +14,13 @@ The gem is tested with Ruby 1.9.2 and Rails 3.0.5 but may well work with other v
|
|
14
14
|
|
15
15
|
Migration:
|
16
16
|
|
17
|
+
rails g model video name:string encoding:attached
|
18
|
+
|
17
19
|
class CreateVideo < ActiveRecord::Migration
|
18
20
|
def self.up
|
19
21
|
create_table :videos do |t|
|
20
|
-
t.string :
|
21
|
-
t.
|
22
|
-
t.integer :encoding_size
|
22
|
+
t.string :name
|
23
|
+
t.attached :encoding
|
23
24
|
|
24
25
|
t.timestamps
|
25
26
|
end
|
@@ -31,16 +32,19 @@ Migration:
|
|
31
32
|
end
|
32
33
|
|
33
34
|
Model:
|
35
|
+
|
36
|
+
class Video < ActiveRecord::Base
|
34
37
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
38
|
+
has_attached :encoding, :styles => {
|
39
|
+
:webm => { :extension => '.webm' },
|
40
|
+
:mp4 => { :extension => '.mp4' },
|
41
|
+
:ogv => { :extension => '.ogv' },
|
42
|
+
}
|
43
|
+
|
44
|
+
after_save do
|
45
|
+
remote.encode(self.encoding.url)
|
46
|
+
end
|
41
47
|
|
42
|
-
after_save do
|
43
|
-
remote.encode(self.encoding.url)
|
44
48
|
end
|
45
49
|
|
46
50
|
Form:
|
@@ -52,8 +56,9 @@ Form:
|
|
52
56
|
View:
|
53
57
|
|
54
58
|
<video>
|
55
|
-
<source src="<%= @video.encoding.url(:
|
56
|
-
<source src="<%= @video.encoding.url(:
|
59
|
+
<source src="<%= @video.encoding.url(:webm)" />
|
60
|
+
<source src="<%= @video.encoding.url(:mp4) %>" />
|
61
|
+
<source src="<%= @video.encoding.url(:ogg) %>" />
|
57
62
|
</video>
|
58
63
|
|
59
64
|
== Advanced
|
@@ -63,6 +68,7 @@ View:
|
|
63
68
|
# app/models/person.rb
|
64
69
|
validates_attached_presence :avatar
|
65
70
|
validates_attached_size :avatar, :in => 2.kilobytes..2.megabytes
|
71
|
+
validates_attached_extension :avatar, :in => %w(jpe jpg jpeg png)
|
66
72
|
|
67
73
|
==== Storage
|
68
74
|
|
data/lib/attached.rb
CHANGED
@@ -10,6 +10,19 @@ module Attached
|
|
10
10
|
end
|
11
11
|
|
12
12
|
|
13
|
+
module Definition
|
14
|
+
def attachment(*args)
|
15
|
+
options = args.extract_options!
|
16
|
+
|
17
|
+
args.each do |name|
|
18
|
+
column("#{name}_identifier", :string, options)
|
19
|
+
column("#{name}_extension", :string, options)
|
20
|
+
column("#{name}_size", :integer, options)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
|
13
26
|
module ClassMethods
|
14
27
|
|
15
28
|
|
data/lib/attached/attachment.rb
CHANGED
@@ -73,9 +73,9 @@ module Attached
|
|
73
73
|
@name = name
|
74
74
|
@instance = instance
|
75
75
|
|
76
|
-
@queue
|
77
|
-
@purge
|
78
|
-
@errors
|
76
|
+
@queue = {}
|
77
|
+
@purge = []
|
78
|
+
@errors = []
|
79
79
|
|
80
80
|
@path = options[:path]
|
81
81
|
@styles = options[:styles]
|
@@ -118,10 +118,7 @@ module Attached
|
|
118
118
|
# @object.avatar.assign(...)
|
119
119
|
|
120
120
|
def assign(file, identifier = "#{Guid.new}")
|
121
|
-
|
122
|
-
if file.is_a?(Attached::Attachment)
|
123
|
-
file = file.file
|
124
|
-
end
|
121
|
+
file = file.file if file.is_a?(Attached::Attachment)
|
125
122
|
|
126
123
|
@file = file.respond_to?(:tempfile) ? file.tempfile : file
|
127
124
|
|
data/lib/attached/railtie.rb
CHANGED
@@ -11,8 +11,8 @@ module Attached
|
|
11
11
|
initializer 'attached.initialize' do
|
12
12
|
ActiveSupport.on_load(:active_record) do
|
13
13
|
ActiveRecord::Base.send :include, Attached
|
14
|
+
ActiveRecord::ConnectionAdapters::TableDefinition.send :include, Attached::Definition
|
14
15
|
end
|
15
16
|
end
|
16
|
-
|
17
17
|
end
|
18
18
|
end
|
data/lib/attached/version.rb
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.3
|
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-03-
|
13
|
+
date: 2011-03-16 00:00:00 -04:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -90,7 +90,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
90
90
|
requirements: []
|
91
91
|
|
92
92
|
rubyforge_project:
|
93
|
-
rubygems_version: 1.6.
|
93
|
+
rubygems_version: 1.6.2
|
94
94
|
signing_key:
|
95
95
|
specification_version: 3
|
96
96
|
summary: An attachment library designed with cloud processors in mind
|