attached 0.2.8 → 0.2.9
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/attached.rb +1 -1
- data/lib/attached/storage/aws.rb +1 -3
- data/lib/attached/storage/base.rb +43 -0
- data/lib/attached/storage/google.rb +1 -3
- data/lib/attached/storage/rackspace.rb +3 -5
- data/lib/attached/version.rb +1 -1
- metadata +3 -3
data/lib/attached.rb
CHANGED
@@ -38,7 +38,7 @@ module Attached
|
|
38
38
|
# Usage:
|
39
39
|
#
|
40
40
|
# has_attached :video
|
41
|
-
# has_attached :video, :storage => :
|
41
|
+
# has_attached :video, :storage => :aws
|
42
42
|
# has_attached :video, styles => { :mov => { :size => "480p", :format => "mov" } }
|
43
43
|
|
44
44
|
def has_attached(name, options = {})
|
data/lib/attached/storage/aws.rb
CHANGED
@@ -56,12 +56,10 @@ module Attached
|
|
56
56
|
# * path - The path to save.
|
57
57
|
|
58
58
|
def save(file, path)
|
59
|
-
file = File.open(file.path)
|
60
|
-
|
61
59
|
directory = connection.directories.get(self.bucket)
|
62
60
|
directory ||= connection.directories.create(self.permissions.merge(:key => self.bucket))
|
63
61
|
|
64
|
-
directory.files.create(self.permissions.merge(:
|
62
|
+
directory.files.create(self.options(path).merge(self.permissions.merge(:key => path, :body => file.read)))
|
65
63
|
end
|
66
64
|
|
67
65
|
|
@@ -21,6 +21,49 @@ module Attached
|
|
21
21
|
end
|
22
22
|
|
23
23
|
|
24
|
+
# Helper for determining options from a file
|
25
|
+
#
|
26
|
+
# Usage:
|
27
|
+
#
|
28
|
+
# options("/images/1.jpg")
|
29
|
+
# options("/images/1.png")
|
30
|
+
# options("/videos/1.mpg")
|
31
|
+
# options("/videos/1.mov")
|
32
|
+
|
33
|
+
def options(path)
|
34
|
+
options = {}
|
35
|
+
type = File.extname(path)
|
36
|
+
|
37
|
+
case type
|
38
|
+
when /tiff/ then options[:content_type] = "image/tiff"
|
39
|
+
when /tif/ then options[:content_type] = "image/tiff"
|
40
|
+
when /jpeg/ then options[:content_type] = "image/jpeg"
|
41
|
+
when /jpe/ then options[:content_type] = "image/jpeg"
|
42
|
+
when /jpg/ then options[:content_type] = "image/jpeg"
|
43
|
+
when /png/ then options[:content_type] = "image/png"
|
44
|
+
when /gif/ then options[:content_type] = "image/gif"
|
45
|
+
when /bmp/ then options[:content_type] = "image/bmp"
|
46
|
+
when /mpeg/ then options[:content_type] = "video/mpeg"
|
47
|
+
when /mpa/ then options[:content_type] = "video/mpeg"
|
48
|
+
when /mpe/ then options[:content_type] = "video/mpeg"
|
49
|
+
when /mpg/ then options[:content_type] = "video/mpeg"
|
50
|
+
when /mov/ then options[:content_type] = "video/mov"
|
51
|
+
when /josn/ then options[:content_type] = "application/json"
|
52
|
+
when /xml/ then options[:content_type] = "application/xml"
|
53
|
+
when /pdf/ then options[:content_type] = "application/pdf"
|
54
|
+
when /rtf/ then options[:content_type] = "application/rtf"
|
55
|
+
when /zip/ then options[:content_type] = "application/zip"
|
56
|
+
when /js/ then options[:content_type] = "application/js"
|
57
|
+
when /html/ then options[:content_type] = "text/html"
|
58
|
+
when /html/ then options[:content_type] = "text/htm"
|
59
|
+
when /txt/ then options[:content_type] = "text/plain"
|
60
|
+
when /csv/ then options[:content_type] = "text/csv"
|
61
|
+
end
|
62
|
+
|
63
|
+
return options
|
64
|
+
end
|
65
|
+
|
66
|
+
|
24
67
|
# Create a new file system storage interface supporting save and destroy operations.
|
25
68
|
#
|
26
69
|
# Usage:
|
@@ -56,12 +56,10 @@ module Attached
|
|
56
56
|
# * path - The path to save.
|
57
57
|
|
58
58
|
def save(file, path)
|
59
|
-
file = File.open(file.path)
|
60
|
-
|
61
59
|
directory = connection.directories.get(self.bucket)
|
62
60
|
directory ||= connection.directories.create(self.permissions.merge(:key => self.bucket))
|
63
61
|
|
64
|
-
directory.files.create(self.permissions.merge(:
|
62
|
+
directory.files.create(self.options(path).merge(self.permissions.merge(:key => path, :body => file.read)))
|
65
63
|
end
|
66
64
|
|
67
65
|
|
@@ -55,12 +55,10 @@ module Attached
|
|
55
55
|
# * path - The path to save.
|
56
56
|
|
57
57
|
def save(file, path)
|
58
|
-
|
58
|
+
directory = connection.directories.get(self.bucket)
|
59
|
+
directory ||= connection.directories.create(self.permissions.merge(:key => self.bucket))
|
59
60
|
|
60
|
-
directory
|
61
|
-
directory ||= connection.directories.create(self.permissions.merge(:key => self.container))
|
62
|
-
|
63
|
-
directory.files.create(self.permissions.merge(:body => file, :key => path))
|
61
|
+
directory.files.create(self.options(path).merge(self.permissions.merge(:key => path, :body => file.read)))
|
64
62
|
end
|
65
63
|
|
66
64
|
|
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.2.
|
5
|
+
version: 0.2.9
|
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-
|
13
|
+
date: 2011-03-01 00:00:00 -05: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.5.
|
93
|
+
rubygems_version: 1.5.3
|
94
94
|
signing_key:
|
95
95
|
specification_version: 3
|
96
96
|
summary: An attachment library designed with cloud processors in mind
|