attached 0.2.1 → 0.2.2
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.
- data/lib/attached/attachment.rb +2 -2
- data/lib/attached/storage.rb +7 -4
- data/lib/attached/storage/aws.rb +26 -25
- data/lib/attached/storage/google.rb +97 -0
- data/lib/attached/storage/rackspace.rb +96 -0
- data/lib/attached/version.rb +1 -1
- metadata +6 -4
data/lib/attached/attachment.rb
CHANGED
@@ -33,11 +33,11 @@ module Attached
|
|
33
33
|
#
|
34
34
|
# Usage:
|
35
35
|
#
|
36
|
-
# Attached::Attachment.options = { :storage => :fs, :path => "
|
36
|
+
# Attached::Attachment.options = { :storage => :fs, :path => ":name/:style/:identifier:extension" }
|
37
37
|
|
38
38
|
def self.options
|
39
39
|
@options ||= {
|
40
|
-
:path => "
|
40
|
+
:path => ":name/:style/:identifier:extension",
|
41
41
|
:default => :original,
|
42
42
|
:medium => :aws,
|
43
43
|
:credentials => {},
|
data/lib/attached/storage.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
|
-
require 'attached/storage/base'
|
2
1
|
require 'attached/storage/aws'
|
2
|
+
require 'attached/storage/google'
|
3
|
+
require 'attached/storage/rackspace'
|
3
4
|
|
4
5
|
module Attached
|
5
6
|
module Storage
|
@@ -9,14 +10,16 @@ module Attached
|
|
9
10
|
#
|
10
11
|
# Usage:
|
11
12
|
#
|
12
|
-
# Attached::Storage.storage()
|
13
13
|
# Attached::Storage.storage(:aws)
|
14
|
-
# Attached::Storage.storage(:
|
14
|
+
# Attached::Storage.storage(:google)
|
15
|
+
# Attached::Storage.storage(:rackspace)
|
15
16
|
|
16
17
|
def self.storage(medium = :aws, credentials = nil)
|
17
18
|
|
18
19
|
case medium
|
19
|
-
when :aws
|
20
|
+
when :aws then return Attached::Storage::AWS.new credentials
|
21
|
+
when :google then return Attached::Storage::Google.new credentials
|
22
|
+
when :rackspace then return Attached::Storage::Rackspace.new credentials
|
20
23
|
else raise "undefined storage medium '#{medium}'"
|
21
24
|
end
|
22
25
|
|
data/lib/attached/storage/aws.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
require 'attached/storage/base'
|
2
2
|
|
3
3
|
begin
|
4
|
-
require '
|
4
|
+
require 'fog'
|
5
5
|
rescue LoadError
|
6
|
-
raise "installation of '
|
6
|
+
raise "installation of 'fog' is required before using 'aws' for storage"
|
7
7
|
end
|
8
8
|
|
9
9
|
|
@@ -12,7 +12,8 @@ module Attached
|
|
12
12
|
class AWS < Base
|
13
13
|
|
14
14
|
|
15
|
-
attr_reader :
|
15
|
+
attr_reader :permissions
|
16
|
+
|
16
17
|
attr_reader :bucket
|
17
18
|
attr_reader :access_key_id
|
18
19
|
attr_reader :secret_access_key
|
@@ -22,13 +23,14 @@ module Attached
|
|
22
23
|
#
|
23
24
|
# Usage:
|
24
25
|
#
|
25
|
-
# Attached::Storage::
|
26
|
-
# Attached::Storage::
|
26
|
+
# Attached::Storage::AWS.new()
|
27
|
+
# Attached::Storage::AWS.new("aws.yml")
|
27
28
|
|
28
29
|
def initialize(credentials)
|
29
30
|
credentials = parse(credentials)
|
30
31
|
|
31
|
-
@
|
32
|
+
@permissions = { :public => true }
|
33
|
+
|
32
34
|
@bucket = credentials[:bucket] || credentials['bucket']
|
33
35
|
@access_key_id = credentials[:access_key_id] || credentials['access_key_id']
|
34
36
|
@secret_access_key = credentials[:secret_access_key] || credentials['secret_access_key']
|
@@ -42,7 +44,7 @@ module Attached
|
|
42
44
|
# storage.host
|
43
45
|
|
44
46
|
def host()
|
45
|
-
"https://#{self.bucket}.s3.amazonaws.com"
|
47
|
+
"https://#{self.bucket}.s3.amazonaws.com/"
|
46
48
|
end
|
47
49
|
|
48
50
|
|
@@ -54,13 +56,12 @@ module Attached
|
|
54
56
|
# * path - The path to save.
|
55
57
|
|
56
58
|
def save(file, path)
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
end
|
59
|
+
file = File.open(file.path)
|
60
|
+
|
61
|
+
directory = connection.directories.get(self.bucket)
|
62
|
+
directory ||= connection.directories.create(self.permissions.merge(:key => self.bucket))
|
63
|
+
|
64
|
+
directory.files.create(self.permissions.merge(:body => file, :key => path))
|
64
65
|
end
|
65
66
|
|
66
67
|
|
@@ -71,22 +72,22 @@ module Attached
|
|
71
72
|
# * path - The path to destroy.
|
72
73
|
|
73
74
|
def destroy(path)
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
75
|
+
directory = connection.directories.get(self.bucket)
|
76
|
+
directory ||= connection.directories.create(self.permissions.merge(:key => self.bucket))
|
77
|
+
|
78
|
+
file = directory.files.get(path)
|
79
|
+
file.destroy if file
|
79
80
|
end
|
80
81
|
|
81
82
|
|
82
83
|
private
|
84
|
+
|
83
85
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
:access_key_id => access_key_id, :secret_access_key => secret_access_key
|
86
|
+
def connection
|
87
|
+
@connection ||= Fog::Storage.new(
|
88
|
+
:aws_secret_access_key => self.secret_access_key,
|
89
|
+
:aws_access_key_id => self.access_key_id,
|
90
|
+
:provider => 'AWS'
|
90
91
|
)
|
91
92
|
end
|
92
93
|
|
@@ -0,0 +1,97 @@
|
|
1
|
+
require 'attached/storage/base'
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'fog'
|
5
|
+
rescue LoadError
|
6
|
+
raise "installation of 'fog' is required before using 'google' for storage"
|
7
|
+
end
|
8
|
+
|
9
|
+
|
10
|
+
module Attached
|
11
|
+
module Storage
|
12
|
+
class Google < Base
|
13
|
+
|
14
|
+
|
15
|
+
attr_reader :permissions
|
16
|
+
|
17
|
+
attr_reader :bucket
|
18
|
+
attr_reader :access_key_id
|
19
|
+
attr_reader :secret_access_key
|
20
|
+
|
21
|
+
|
22
|
+
# Create a new AWS interface supporting save and destroy operations.
|
23
|
+
#
|
24
|
+
# Usage:
|
25
|
+
#
|
26
|
+
# Attached::Storage::Google.new()
|
27
|
+
# Attached::Storage::Google.new("google.yml")
|
28
|
+
|
29
|
+
def initialize(credentials)
|
30
|
+
credentials = parse(credentials)
|
31
|
+
|
32
|
+
@permissions = { :public => true }
|
33
|
+
|
34
|
+
@bucket = credentials[:bucket] || credentials['bucket']
|
35
|
+
@access_key_id = credentials[:access_key_id] || credentials['access_key_id']
|
36
|
+
@secret_access_key = credentials[:secret_access_key] || credentials['secret_access_key']
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
# Access the host (e.g. bucket.s3.amazonaws.com) for a storage service.
|
41
|
+
#
|
42
|
+
# Usage:
|
43
|
+
#
|
44
|
+
# storage.host
|
45
|
+
|
46
|
+
def host()
|
47
|
+
"https://#{self.bucket}.commondatastorage.googleapis.com/"
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
# Save a file to a given path on AWS S3.
|
52
|
+
#
|
53
|
+
# Parameters:
|
54
|
+
#
|
55
|
+
# * file - The file to save.
|
56
|
+
# * path - The path to save.
|
57
|
+
|
58
|
+
def save(file, path)
|
59
|
+
file = File.open(file.path)
|
60
|
+
|
61
|
+
directory = connection.directories.get(self.bucket)
|
62
|
+
directory ||= connection.directories.create(self.permissions.merge(:key => self.bucket))
|
63
|
+
|
64
|
+
directory.files.create(self.permissions.merge(:body => file, :key => path))
|
65
|
+
end
|
66
|
+
|
67
|
+
|
68
|
+
# Destroy a file at a given path on AWS S3.
|
69
|
+
#
|
70
|
+
# Parameters:
|
71
|
+
#
|
72
|
+
# * path - The path to destroy.
|
73
|
+
|
74
|
+
def destroy(path)
|
75
|
+
directory = connection.directories.get(self.bucket)
|
76
|
+
directory ||= connection.directories.create(self.permissions.merge(:key => self.bucket))
|
77
|
+
|
78
|
+
file = directory.files.get(path)
|
79
|
+
file.destroy if file
|
80
|
+
end
|
81
|
+
|
82
|
+
|
83
|
+
private
|
84
|
+
|
85
|
+
|
86
|
+
def connection
|
87
|
+
@connection ||= Fog::Storage.new(
|
88
|
+
:google_storage_secret_access_key => self.secret_access_key,
|
89
|
+
:google_storage_access_key_id => self.access_key_id,
|
90
|
+
:provider => 'Google'
|
91
|
+
)
|
92
|
+
end
|
93
|
+
|
94
|
+
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
@@ -0,0 +1,96 @@
|
|
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
|
8
|
+
|
9
|
+
|
10
|
+
module Attached
|
11
|
+
module Storage
|
12
|
+
class Rackspace < Base
|
13
|
+
|
14
|
+
|
15
|
+
attr_reader :permissions
|
16
|
+
attr_reader :container
|
17
|
+
attr_reader :username
|
18
|
+
attr_reader :api_key
|
19
|
+
|
20
|
+
|
21
|
+
# Create a new AWS interface supporting save and destroy operations.
|
22
|
+
#
|
23
|
+
# Usage:
|
24
|
+
#
|
25
|
+
# Attached::Storage::Rackspace.new()
|
26
|
+
# Attached::Storage::Rackspace.new("rackspace.yml")
|
27
|
+
|
28
|
+
def initialize(credentials)
|
29
|
+
credentials = parse(credentials)
|
30
|
+
|
31
|
+
@permissions = { :public => true }
|
32
|
+
|
33
|
+
@container = credentials[:container] || credentials['container']
|
34
|
+
@username = credentials[:username] || credentials['username']
|
35
|
+
@api_key = credentials[:api_key] || credentials['api_key']
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
# Access the host (e.g. bucket.s3.amazonaws.com) for a storage service.
|
40
|
+
#
|
41
|
+
# Usage:
|
42
|
+
#
|
43
|
+
# storage.host
|
44
|
+
|
45
|
+
def host()
|
46
|
+
"https://#{self.bucket}.s3.amazonaws.com/"
|
47
|
+
end
|
48
|
+
|
49
|
+
|
50
|
+
# Save a file to a given path on AWS S3.
|
51
|
+
#
|
52
|
+
# Parameters:
|
53
|
+
#
|
54
|
+
# * file - The file to save.
|
55
|
+
# * path - The path to save.
|
56
|
+
|
57
|
+
def save(file, path)
|
58
|
+
file = File.open(file.path)
|
59
|
+
|
60
|
+
directory = connection.directories.get(self.bucket)
|
61
|
+
directory ||= connection.directories.create(self.permissions.merge(:key => self.bucket))
|
62
|
+
|
63
|
+
directory.files.create(self.permissions.merge(:body => file, :key => path))
|
64
|
+
end
|
65
|
+
|
66
|
+
|
67
|
+
# Destroy a file at a given path on AWS S3.
|
68
|
+
#
|
69
|
+
# Parameters:
|
70
|
+
#
|
71
|
+
# * path - The path to destroy.
|
72
|
+
|
73
|
+
def destroy(path)
|
74
|
+
directory = connection.directories.get(self.bucket)
|
75
|
+
directory ||= connection.directories.create(self.permissions.merge(:key => self.bucket))
|
76
|
+
|
77
|
+
file = directory.files.get(path)
|
78
|
+
file.destroy if file
|
79
|
+
end
|
80
|
+
|
81
|
+
|
82
|
+
private
|
83
|
+
|
84
|
+
|
85
|
+
def connection
|
86
|
+
@connection ||= Fog::Storage.new(
|
87
|
+
:rackspace_username => self.username,
|
88
|
+
:rackspace_api_key => self.api_key,
|
89
|
+
:provider => 'Rackspace'
|
90
|
+
)
|
91
|
+
end
|
92
|
+
|
93
|
+
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
data/lib/attached/version.rb
CHANGED
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 2
|
8
|
-
-
|
9
|
-
version: 0.2.
|
8
|
+
- 2
|
9
|
+
version: 0.2.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Kevin Sylvestre
|
@@ -14,11 +14,11 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-01-
|
17
|
+
date: 2011-01-20 00:00:00 -04:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
|
-
name:
|
21
|
+
name: fog
|
22
22
|
prerelease: false
|
23
23
|
requirement: &id001 !ruby/object:Gem::Requirement
|
24
24
|
none: false
|
@@ -63,6 +63,8 @@ files:
|
|
63
63
|
- lib/attached/storage/aws.rb
|
64
64
|
- lib/attached/storage/base.rb
|
65
65
|
- lib/attached/storage/error.rb
|
66
|
+
- lib/attached/storage/google.rb
|
67
|
+
- lib/attached/storage/rackspace.rb
|
66
68
|
- lib/attached/storage.rb
|
67
69
|
- lib/attached/version.rb
|
68
70
|
- lib/attached.rb
|