attached 0.5.9 → 0.6.0
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.
- checksums.yaml +4 -4
- data/README.rdoc +7 -1
- data/lib/attached/attachment.rb +1 -0
- data/lib/attached/storage/aws.rb +11 -73
- data/lib/attached/storage/fog.rb +98 -0
- data/lib/attached/storage/google.rb +8 -70
- data/lib/attached/storage/local.rb +1 -0
- data/lib/attached/storage/rackspace.rb +9 -70
- data/lib/attached/version.rb +1 -1
- data/test/dummy/config/aws.yml +14 -0
- data/test/dummy/config/google.yml +0 -0
- data/test/dummy/config/rackspace.yml +0 -0
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/log/test.log +2525 -0
- data/test/dummy/public/system/audios/files/full/08ddd220-3b8a-4bc3-b20f-a01c7c7be816.aac +0 -0
- data/test/dummy/public/system/audios/files/full/57905e8e-356e-4705-9b60-ebf2ca941bbb.aac +0 -0
- data/test/dummy/public/system/audios/files/full/6ba84723-c6b3-4dcc-9fdd-dab340dfe82b.aac +0 -0
- data/test/dummy/public/system/audios/files/full/a77a2cc0-8c48-405e-9801-33642ba2ba60.aac +0 -0
- data/test/dummy/public/system/audios/files/full/f1a0c007-9bfc-4c65-b302-f7a5bd93ca3c.aac +0 -0
- data/test/dummy/public/system/audios/files/full/fbac7738-20ef-4a65-a4b4-943fe3afb379.aac +0 -0
- data/test/dummy/public/system/audios/files/large/08ddd220-3b8a-4bc3-b20f-a01c7c7be816.aac +0 -0
- data/test/dummy/public/system/audios/files/large/57905e8e-356e-4705-9b60-ebf2ca941bbb.aac +0 -0
- data/test/dummy/public/system/audios/files/large/6ba84723-c6b3-4dcc-9fdd-dab340dfe82b.aac +0 -0
- data/test/dummy/public/system/audios/files/large/a77a2cc0-8c48-405e-9801-33642ba2ba60.aac +0 -0
- data/test/dummy/public/system/audios/files/large/f1a0c007-9bfc-4c65-b302-f7a5bd93ca3c.aac +0 -0
- data/test/dummy/public/system/audios/files/large/fbac7738-20ef-4a65-a4b4-943fe3afb379.aac +0 -0
- data/test/dummy/public/system/audios/files/original/08ddd220-3b8a-4bc3-b20f-a01c7c7be816.wav +0 -0
- data/test/dummy/public/system/audios/files/original/57905e8e-356e-4705-9b60-ebf2ca941bbb.wav +0 -0
- data/test/dummy/public/system/audios/files/original/6ba84723-c6b3-4dcc-9fdd-dab340dfe82b.wav +0 -0
- data/test/dummy/public/system/audios/files/original/a77a2cc0-8c48-405e-9801-33642ba2ba60.wav +0 -0
- data/test/dummy/public/system/audios/files/original/f1a0c007-9bfc-4c65-b302-f7a5bd93ca3c.wav +0 -0
- data/test/dummy/public/system/audios/files/original/fbac7738-20ef-4a65-a4b4-943fe3afb379.wav +0 -0
- data/test/dummy/public/system/audios/files/small/08ddd220-3b8a-4bc3-b20f-a01c7c7be816.aac +0 -0
- data/test/dummy/public/system/audios/files/small/57905e8e-356e-4705-9b60-ebf2ca941bbb.aac +0 -0
- data/test/dummy/public/system/audios/files/small/6ba84723-c6b3-4dcc-9fdd-dab340dfe82b.aac +0 -0
- data/test/dummy/public/system/audios/files/small/a77a2cc0-8c48-405e-9801-33642ba2ba60.aac +0 -0
- data/test/dummy/public/system/audios/files/small/f1a0c007-9bfc-4c65-b302-f7a5bd93ca3c.aac +0 -0
- data/test/dummy/public/system/audios/files/small/fbac7738-20ef-4a65-a4b4-943fe3afb379.aac +0 -0
- data/test/dummy/public/system/images/files/full/38387849-e947-467d-ae17-19a4fdaaa8f3.jpg +0 -0
- data/test/dummy/public/system/images/files/full/6142216b-5606-4376-b815-39da7ebac624.jpg +0 -0
- data/test/dummy/public/system/images/files/full/82cf7f7a-7764-4929-a5b4-a7d4dc21289e.jpg +0 -0
- data/test/dummy/public/system/images/files/full/83eefeeb-afaa-4a88-8114-30ccf6a208aa.jpg +0 -0
- data/test/dummy/public/system/images/files/full/dc220293-a2fc-4012-ac83-8c2b16605480.jpg +0 -0
- data/test/dummy/public/system/images/files/full/fbf7f894-6322-4233-b2a7-0fae7f44f642.jpg +0 -0
- data/test/dummy/public/system/images/files/large/38387849-e947-467d-ae17-19a4fdaaa8f3.jpg +0 -0
- data/test/dummy/public/system/images/files/large/6142216b-5606-4376-b815-39da7ebac624.jpg +0 -0
- data/test/dummy/public/system/images/files/large/82cf7f7a-7764-4929-a5b4-a7d4dc21289e.jpg +0 -0
- data/test/dummy/public/system/images/files/large/83eefeeb-afaa-4a88-8114-30ccf6a208aa.jpg +0 -0
- data/test/dummy/public/system/images/files/large/dc220293-a2fc-4012-ac83-8c2b16605480.jpg +0 -0
- data/test/dummy/public/system/images/files/large/fbf7f894-6322-4233-b2a7-0fae7f44f642.jpg +0 -0
- data/test/dummy/public/system/images/files/original/38387849-e947-467d-ae17-19a4fdaaa8f3.png +0 -0
- data/test/dummy/public/system/images/files/original/6142216b-5606-4376-b815-39da7ebac624.png +0 -0
- data/test/dummy/public/system/images/files/original/82cf7f7a-7764-4929-a5b4-a7d4dc21289e.png +0 -0
- data/test/dummy/public/system/images/files/original/83eefeeb-afaa-4a88-8114-30ccf6a208aa.png +0 -0
- data/test/dummy/public/system/images/files/original/dc220293-a2fc-4012-ac83-8c2b16605480.png +0 -0
- data/test/dummy/public/system/images/files/original/fbf7f894-6322-4233-b2a7-0fae7f44f642.png +0 -0
- data/test/dummy/public/system/images/files/small/38387849-e947-467d-ae17-19a4fdaaa8f3.jpg +0 -0
- data/test/dummy/public/system/images/files/small/6142216b-5606-4376-b815-39da7ebac624.jpg +0 -0
- data/test/dummy/public/system/images/files/small/82cf7f7a-7764-4929-a5b4-a7d4dc21289e.jpg +0 -0
- data/test/dummy/public/system/images/files/small/83eefeeb-afaa-4a88-8114-30ccf6a208aa.jpg +0 -0
- data/test/dummy/public/system/images/files/small/dc220293-a2fc-4012-ac83-8c2b16605480.jpg +0 -0
- data/test/dummy/public/system/images/files/small/fbf7f894-6322-4233-b2a7-0fae7f44f642.jpg +0 -0
- data/test/dummy/public/system/images/files/thumb/38387849-e947-467d-ae17-19a4fdaaa8f3.jpg +0 -0
- data/test/dummy/public/system/images/files/thumb/6142216b-5606-4376-b815-39da7ebac624.jpg +0 -0
- data/test/dummy/public/system/images/files/thumb/82cf7f7a-7764-4929-a5b4-a7d4dc21289e.jpg +0 -0
- data/test/dummy/public/system/images/files/thumb/83eefeeb-afaa-4a88-8114-30ccf6a208aa.jpg +0 -0
- data/test/dummy/public/system/images/files/thumb/dc220293-a2fc-4012-ac83-8c2b16605480.jpg +0 -0
- data/test/dummy/public/system/images/files/thumb/fbf7f894-6322-4233-b2a7-0fae7f44f642.jpg +0 -0
- metadata +117 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e04c7e6d4ae5b9e01aa1bf4e2e6d9f2d7450561f
|
|
4
|
+
data.tar.gz: 96a3e72f4edd2adff2a8245ba0e761971219025a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 13c9e025f9b53c7eff234b0cf64daf44e24ee4b1c1e1a41735f485d4c7e872472c9391653730ae4427f0ca38e6400d9beae15085b8912395f8d1ed085061be7e
|
|
7
|
+
data.tar.gz: ecee752043b0387cec8b7090cacde98876c185692dda2f2ad8076d3533ef989647d02d81e091ba95bad3609b6bfd1d7610df1b315fc62078e35bdae88d9a0c2f
|
data/README.rdoc
CHANGED
|
@@ -6,6 +6,7 @@ Attached is a Ruby on Rails file attachment tool that lets users upload to the c
|
|
|
6
6
|
|
|
7
7
|
The gem is tested with:
|
|
8
8
|
|
|
9
|
+
* Ruby on Rails 4.0.0.rc
|
|
9
10
|
* Ruby on Rails 3.1.9
|
|
10
11
|
* Ruby on Rails 3.2.10
|
|
11
12
|
* Ruby (MRI) 2.0.0
|
|
@@ -159,7 +160,7 @@ View:
|
|
|
159
160
|
=== Aliases
|
|
160
161
|
|
|
161
162
|
# app/initializer/attached.rb
|
|
162
|
-
Attached::Attachment.options[:alias] = https://storage.ksylvest.com/
|
|
163
|
+
Attached::Attachment.options[:alias] = "https://storage.ksylvest.com/"
|
|
163
164
|
|
|
164
165
|
# app/initializer/attached.rb
|
|
165
166
|
Attached::Attachment.options[:aliases] = %w(
|
|
@@ -169,6 +170,11 @@ View:
|
|
|
169
170
|
https://d.storage.ksylvest.com/
|
|
170
171
|
)
|
|
171
172
|
|
|
173
|
+
=== Metadata
|
|
174
|
+
|
|
175
|
+
# app/initializers/attached.rb
|
|
176
|
+
Attached::Attachment.options[:metadata] = { 'Cache-Control' => 'max-age=3153600' }
|
|
177
|
+
|
|
172
178
|
== Status
|
|
173
179
|
|
|
174
180
|
{<img src="https://travis-ci.org/ksylvest/attached.png" />}[https://travis-ci.org/ksylvest/attached]
|
data/lib/attached/attachment.rb
CHANGED
data/lib/attached/storage/aws.rb
CHANGED
|
@@ -1,18 +1,11 @@
|
|
|
1
|
-
require 'attached/storage/
|
|
2
|
-
|
|
3
|
-
begin
|
|
4
|
-
require 'fog'
|
|
5
|
-
rescue LoadError
|
|
6
|
-
raise "installation of 'fog' is required before using 'aws' for storage"
|
|
7
|
-
end
|
|
1
|
+
require 'attached/storage/fog'
|
|
2
|
+
require 'fog'
|
|
8
3
|
|
|
9
4
|
|
|
10
5
|
module Attached
|
|
11
6
|
module Storage
|
|
12
|
-
class AWS <
|
|
13
|
-
|
|
7
|
+
class AWS < Fog
|
|
14
8
|
|
|
15
|
-
attr_reader :permissions
|
|
16
9
|
|
|
17
10
|
attr_reader :bucket
|
|
18
11
|
attr_reader :access_key_id
|
|
@@ -27,9 +20,9 @@ module Attached
|
|
|
27
20
|
# Attached::Storage::AWS.new("aws.yml")
|
|
28
21
|
|
|
29
22
|
def initialize(credentials)
|
|
30
|
-
|
|
23
|
+
super
|
|
31
24
|
|
|
32
|
-
|
|
25
|
+
credentials = parse(credentials)
|
|
33
26
|
|
|
34
27
|
@bucket = credentials[:bucket] || credentials['bucket']
|
|
35
28
|
@access_key_id = credentials[:access_key_id] || credentials['access_key_id']
|
|
@@ -50,71 +43,16 @@ module Attached
|
|
|
50
43
|
end
|
|
51
44
|
|
|
52
45
|
|
|
53
|
-
|
|
54
|
-
#
|
|
55
|
-
# Parameters:
|
|
56
|
-
#
|
|
57
|
-
# * file - The file to save.
|
|
58
|
-
# * path - The path to save.
|
|
59
|
-
|
|
60
|
-
def save(file, path)
|
|
61
|
-
file = File.open(file.path)
|
|
62
|
-
|
|
63
|
-
directory = connection.directories.get(self.bucket)
|
|
64
|
-
directory ||= connection.directories.create(self.permissions.merge(:key => self.bucket))
|
|
65
|
-
|
|
66
|
-
directory.files.create(self.options(path).merge(self.permissions.merge(:key => path, :body => file)))
|
|
67
|
-
|
|
68
|
-
file.close
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
# Retrieve a file from a given path.
|
|
73
|
-
#
|
|
74
|
-
# Parameters:
|
|
75
|
-
#
|
|
76
|
-
# * path - The path to retrieve.
|
|
77
|
-
|
|
78
|
-
def retrieve(path)
|
|
79
|
-
directory = connection.directories.get(self.bucket)
|
|
80
|
-
directory ||= connection.directories.create(self.permissions.merge(:key => self.bucket))
|
|
81
|
-
|
|
82
|
-
file = directory.files.get(path)
|
|
83
|
-
|
|
84
|
-
body = file.body
|
|
85
|
-
|
|
86
|
-
extname = File.extname(path)
|
|
87
|
-
basename = File.basename(path, extname)
|
|
88
|
-
|
|
89
|
-
file = Tempfile.new([basename, extname])
|
|
90
|
-
file.binmode
|
|
91
|
-
file.write(body)
|
|
92
|
-
file.rewind
|
|
93
|
-
|
|
94
|
-
file
|
|
95
|
-
end
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
# Destroy a file at a given path.
|
|
99
|
-
#
|
|
100
|
-
# Parameters:
|
|
101
|
-
#
|
|
102
|
-
# * path - The path to destroy.
|
|
103
|
-
|
|
104
|
-
def destroy(path)
|
|
105
|
-
directory = connection.directories.get(self.bucket)
|
|
106
|
-
directory ||= connection.directories.create(self.permissions.merge(:key => self.bucket))
|
|
107
|
-
|
|
108
|
-
file = directory.files.get(path)
|
|
109
|
-
file.destroy if file
|
|
110
|
-
end
|
|
46
|
+
private
|
|
111
47
|
|
|
112
48
|
|
|
113
|
-
|
|
49
|
+
def directory()
|
|
50
|
+
connection.directories.get(self.bucket) || connection.directories.create(self.defaults.merge(:key => self.bucket))
|
|
51
|
+
end
|
|
114
52
|
|
|
115
53
|
|
|
116
54
|
def connection
|
|
117
|
-
@connection ||= Fog::Storage.new(
|
|
55
|
+
@connection ||= ::Fog::Storage.new(
|
|
118
56
|
:aws_secret_access_key => self.secret_access_key,
|
|
119
57
|
:aws_access_key_id => self.access_key_id,
|
|
120
58
|
:provider => 'AWS'
|
|
@@ -124,4 +62,4 @@ module Attached
|
|
|
124
62
|
|
|
125
63
|
end
|
|
126
64
|
end
|
|
127
|
-
end
|
|
65
|
+
end
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
require 'attached/storage/base'
|
|
2
|
+
require 'fog'
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
module Attached
|
|
6
|
+
module Storage
|
|
7
|
+
class Fog < Base
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
attr_reader :defaults
|
|
11
|
+
|
|
12
|
+
attr_reader :bucket
|
|
13
|
+
attr_reader :access_key_id
|
|
14
|
+
attr_reader :secret_access_key
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
# Create a new interface supporting save and destroy operations (should be overridden and called).
|
|
18
|
+
|
|
19
|
+
def initialize(credentials)
|
|
20
|
+
@defaults = { :public => true, :metadata => Attached::Attachment.options[:metadata] }
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
# Access the host for a storage service (must override).
|
|
25
|
+
#
|
|
26
|
+
# Usage:
|
|
27
|
+
#
|
|
28
|
+
# storage.host
|
|
29
|
+
|
|
30
|
+
def host()
|
|
31
|
+
raise NotImplementedError.new
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
# Save a file to a given path.
|
|
36
|
+
#
|
|
37
|
+
# Parameters:
|
|
38
|
+
#
|
|
39
|
+
# * file - The file to save.
|
|
40
|
+
# * path - The path to save.
|
|
41
|
+
|
|
42
|
+
def save(file, path)
|
|
43
|
+
file = File.open(file.path)
|
|
44
|
+
directory.files.create(self.options(path).merge(self.defaults.merge(:key => path, :body => file)))
|
|
45
|
+
file.close
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
# Retrieve a file from a given path.
|
|
50
|
+
#
|
|
51
|
+
# Parameters:
|
|
52
|
+
#
|
|
53
|
+
# * path - The path to retrieve.
|
|
54
|
+
|
|
55
|
+
def retrieve(path)
|
|
56
|
+
file = directory.files.get(path)
|
|
57
|
+
|
|
58
|
+
body = file.body
|
|
59
|
+
|
|
60
|
+
extname = File.extname(path)
|
|
61
|
+
basename = File.basename(path, extname)
|
|
62
|
+
|
|
63
|
+
file = Tempfile.new([basename, extname])
|
|
64
|
+
file.binmode
|
|
65
|
+
file.write(body)
|
|
66
|
+
file.rewind
|
|
67
|
+
|
|
68
|
+
file
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
# Destroy a file at a given path.
|
|
73
|
+
#
|
|
74
|
+
# Parameters:
|
|
75
|
+
#
|
|
76
|
+
# * path - The path to destroy.
|
|
77
|
+
|
|
78
|
+
def destroy(path)
|
|
79
|
+
directory.files.get(path).destroy if directory.files.head(path)
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
private
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def directory
|
|
87
|
+
raise NotImplementedError.new
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def connection
|
|
92
|
+
raise NotImplementedError.new
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
end
|
|
@@ -1,18 +1,10 @@
|
|
|
1
|
-
require 'attached/storage/
|
|
2
|
-
|
|
3
|
-
begin
|
|
4
|
-
require 'fog'
|
|
5
|
-
rescue LoadError
|
|
6
|
-
raise "installation of 'fog' is required before using 'google' for storage"
|
|
7
|
-
end
|
|
1
|
+
require 'attached/storage/fog'
|
|
8
2
|
|
|
9
3
|
|
|
10
4
|
module Attached
|
|
11
5
|
module Storage
|
|
12
|
-
class Google <
|
|
13
|
-
|
|
6
|
+
class Google < Fog
|
|
14
7
|
|
|
15
|
-
attr_reader :permissions
|
|
16
8
|
|
|
17
9
|
attr_reader :bucket
|
|
18
10
|
attr_reader :access_key_id
|
|
@@ -27,9 +19,10 @@ module Attached
|
|
|
27
19
|
# Attached::Storage::Google.new("google.yml")
|
|
28
20
|
|
|
29
21
|
def initialize(credentials)
|
|
22
|
+
super
|
|
23
|
+
|
|
30
24
|
credentials = parse(credentials)
|
|
31
25
|
|
|
32
|
-
@permissions = { :public => true }
|
|
33
26
|
|
|
34
27
|
@bucket = credentials[:bucket] || credentials['bucket']
|
|
35
28
|
@access_key_id = credentials[:access_key_id] || credentials['access_key_id']
|
|
@@ -50,71 +43,16 @@ module Attached
|
|
|
50
43
|
end
|
|
51
44
|
|
|
52
45
|
|
|
53
|
-
|
|
54
|
-
#
|
|
55
|
-
# Parameters:
|
|
56
|
-
#
|
|
57
|
-
# * file - The file to save.
|
|
58
|
-
# * path - The path to save.
|
|
59
|
-
|
|
60
|
-
def save(file, path)
|
|
61
|
-
file = File.open(file.path)
|
|
62
|
-
|
|
63
|
-
directory = connection.directories.get(self.bucket)
|
|
64
|
-
directory ||= connection.directories.create(self.permissions.merge(:key => self.bucket))
|
|
65
|
-
|
|
66
|
-
directory.files.create(self.options(path).merge(self.permissions.merge(:key => path, :body => file)))
|
|
67
|
-
|
|
68
|
-
file.close
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
# Retrieve a file from a given path.
|
|
73
|
-
#
|
|
74
|
-
# Parameters:
|
|
75
|
-
#
|
|
76
|
-
# * path - The path to retrieve.
|
|
77
|
-
|
|
78
|
-
def retrieve(path)
|
|
79
|
-
directory = connection.directories.get(self.bucket)
|
|
80
|
-
directory ||= connection.directories.create(self.permissions.merge(:key => self.bucket))
|
|
81
|
-
|
|
82
|
-
file = directory.files.get(path)
|
|
83
|
-
|
|
84
|
-
body = file.body
|
|
85
|
-
|
|
86
|
-
extname = File.extname(path)
|
|
87
|
-
basename = File.basename(path, extname)
|
|
88
|
-
|
|
89
|
-
file = Tempfile.new([basename, extname])
|
|
90
|
-
file.binmode
|
|
91
|
-
file.write(body)
|
|
92
|
-
file.rewind
|
|
93
|
-
|
|
94
|
-
file
|
|
95
|
-
end
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
# Destroy a file at a given path.
|
|
99
|
-
#
|
|
100
|
-
# Parameters:
|
|
101
|
-
#
|
|
102
|
-
# * path - The path to destroy.
|
|
46
|
+
private
|
|
103
47
|
|
|
104
|
-
def destroy(path)
|
|
105
|
-
directory = connection.directories.get(self.bucket)
|
|
106
|
-
directory ||= connection.directories.create(self.permissions.merge(:key => self.bucket))
|
|
107
48
|
|
|
108
|
-
|
|
109
|
-
|
|
49
|
+
def directory()
|
|
50
|
+
connection.directories.get(self.bucket) || connection.directories.create(self.defaults.merge(:key => self.bucket))
|
|
110
51
|
end
|
|
111
52
|
|
|
112
53
|
|
|
113
|
-
private
|
|
114
|
-
|
|
115
|
-
|
|
116
54
|
def connection
|
|
117
|
-
@connection ||= Fog::Storage.new(
|
|
55
|
+
@connection ||= ::Fog::Storage.new(
|
|
118
56
|
:google_storage_secret_access_key => self.secret_access_key,
|
|
119
57
|
:google_storage_access_key_id => self.access_key_id,
|
|
120
58
|
:provider => 'Google'
|
|
@@ -1,18 +1,12 @@
|
|
|
1
1
|
require 'attached/storage/base'
|
|
2
|
-
|
|
3
|
-
begin
|
|
4
|
-
require 'fog'
|
|
5
|
-
rescue LoadError
|
|
6
|
-
raise "installation of 'fog' is required before using 'rackspace' for storage"
|
|
7
|
-
end
|
|
2
|
+
require 'fog'
|
|
8
3
|
|
|
9
4
|
|
|
10
5
|
module Attached
|
|
11
6
|
module Storage
|
|
12
|
-
class Rackspace <
|
|
7
|
+
class Rackspace < Fog
|
|
13
8
|
|
|
14
9
|
|
|
15
|
-
attr_reader :permissions
|
|
16
10
|
attr_reader :container
|
|
17
11
|
attr_reader :username
|
|
18
12
|
attr_reader :api_key
|
|
@@ -26,9 +20,9 @@ module Attached
|
|
|
26
20
|
# Attached::Storage::Rackspace.new("rackspace.yml")
|
|
27
21
|
|
|
28
22
|
def initialize(credentials)
|
|
29
|
-
|
|
23
|
+
super
|
|
30
24
|
|
|
31
|
-
|
|
25
|
+
credentials = parse(credentials)
|
|
32
26
|
|
|
33
27
|
@container = credentials[:container] || credentials['container']
|
|
34
28
|
@username = credentials[:username] || credentials['username']
|
|
@@ -49,71 +43,16 @@ module Attached
|
|
|
49
43
|
end
|
|
50
44
|
|
|
51
45
|
|
|
52
|
-
|
|
53
|
-
#
|
|
54
|
-
# Parameters:
|
|
55
|
-
#
|
|
56
|
-
# * file - The file to save.
|
|
57
|
-
# * path - The path to save.
|
|
58
|
-
|
|
59
|
-
def save(file, path)
|
|
60
|
-
file = File.open(file.path)
|
|
61
|
-
|
|
62
|
-
directory = connection.directories.get(self.container)
|
|
63
|
-
directory ||= connection.directories.create(self.permissions.merge(:key => self.container))
|
|
64
|
-
|
|
65
|
-
directory.files.create(self.options(path).merge(self.permissions.merge(:key => path, :body => file)))
|
|
66
|
-
|
|
67
|
-
file.close
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
# Retrieve a file from a given path.
|
|
72
|
-
#
|
|
73
|
-
# Parameters:
|
|
74
|
-
#
|
|
75
|
-
# * path - The path to retrieve.
|
|
76
|
-
|
|
77
|
-
def retrieve(path)
|
|
78
|
-
directory = connection.directories.get(self.bucket)
|
|
79
|
-
directory ||= connection.directories.create(self.permissions.merge(:key => self.bucket))
|
|
80
|
-
|
|
81
|
-
file = directory.files.get(path)
|
|
82
|
-
|
|
83
|
-
body = file.body
|
|
84
|
-
|
|
85
|
-
extname = File.extname(path)
|
|
86
|
-
basename = File.basename(path, extname)
|
|
87
|
-
|
|
88
|
-
file = Tempfile.new([basename, extname])
|
|
89
|
-
file.binmode
|
|
90
|
-
file.write(body)
|
|
91
|
-
file.rewind
|
|
92
|
-
|
|
93
|
-
file
|
|
94
|
-
end
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
# Destroy a file at a given path.
|
|
98
|
-
#
|
|
99
|
-
# Parameters:
|
|
100
|
-
#
|
|
101
|
-
# * path - The path to destroy.
|
|
102
|
-
|
|
103
|
-
def destroy(path)
|
|
104
|
-
directory = connection.directories.get(self.container)
|
|
105
|
-
directory ||= connection.directories.create(self.permissions.merge(:key => self.container))
|
|
106
|
-
|
|
107
|
-
file = directory.files.get(path)
|
|
108
|
-
file.destroy if file
|
|
109
|
-
end
|
|
46
|
+
private
|
|
110
47
|
|
|
111
48
|
|
|
112
|
-
|
|
49
|
+
def directory()
|
|
50
|
+
connection.directories.get(self.container) || connection.directories.create(self.defaults.merge(:key => self.container))
|
|
51
|
+
end
|
|
113
52
|
|
|
114
53
|
|
|
115
54
|
def connection
|
|
116
|
-
@connection ||= Fog::Storage.new(
|
|
55
|
+
@connection ||= ::Fog::Storage.new(
|
|
117
56
|
:rackspace_username => self.username,
|
|
118
57
|
:rackspace_api_key => self.api_key,
|
|
119
58
|
:provider => 'Rackspace'
|