Class: RemoteFiles::FogStore
Instance Attribute Summary
#identifier
Instance Method Summary
collapse
#[]=, #file_from_url, #initialize, #options, #read_only?, #to_sym
Instance Method Details
#connection ⇒ Object
63
64
65
66
67
68
|
# File 'lib/remote_files/fog_store.rb', line 63
def connection
connection_options = options.dup
connection_options.delete(:directory)
connection_options.delete(:public)
@connection ||= Fog::Storage.new(connection_options)
end
|
#delete!(identifier) ⇒ Object
57
58
59
60
61
|
# File 'lib/remote_files/fog_store.rb', line 57
def delete!(identifier)
connection.delete_object(directory.key, identifier)
rescue Fog::Errors::NotFound, Excon::Errors::NotFound
raise NotFoundError, $!.message, $!.backtrace
end
|
#directory ⇒ Object
74
75
76
|
# File 'lib/remote_files/fog_store.rb', line 74
def directory
@directory ||= lookup_directory || create_directory
end
|
#directory_name ⇒ Object
70
71
72
|
# File 'lib/remote_files/fog_store.rb', line 70
def directory_name
options[:directory]
end
|
#retrieve!(identifier) ⇒ Object
21
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/remote_files/fog_store.rb', line 21
def retrieve!(identifier)
fog_file = directory.files.get(identifier)
raise NotFoundError, "#{identifier} not found in #{self.identifier} store" if fog_file.nil?
File.new(identifier,
:content => fog_file.body,
:content_type => fog_file.content_type,
:stored_in => [self]
)
rescue Fog::Errors::Error, Excon::Errors::Error
raise RemoteFiles::Error, $!.message, $!.backtrace
end
|
#store!(file) ⇒ Object
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
# File 'lib/remote_files/fog_store.rb', line 5
def store!(file)
success = directory.files.create(
:body => file.content,
:content_type => file.content_type,
:key => file.identifier,
:public => options[:public],
:encryption => options[:encryption]
)
raise RemoteFiles::Error unless success
true
rescue Fog::Errors::Error, Excon::Errors::Error
raise RemoteFiles::Error, $!.message, $!.backtrace
end
|
#url(identifier) ⇒ Object
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/remote_files/fog_store.rb', line 35
def url(identifier)
case options[:provider]
when 'AWS'
"https://#{aws_host}/#{directory_name}/#{Fog::AWS.escape(identifier)}"
when 'Rackspace'
"https://storage.cloudfiles.com/#{directory_name}/#{Fog::Rackspace.escape(identifier, '/')}"
else
raise "#{self.class.name}#url was not implemented for the #{options[:provider]} provider"
end
end
|
#url_matcher ⇒ Object
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/remote_files/fog_store.rb', line 46
def url_matcher
@url_matcher ||= case options[:provider]
when 'AWS'
/https?:\/\/s3[^\.]*.amazonaws.com\/#{directory_name}\/(.*)/
when 'Rackspace'
/https?:\/\/storage.cloudfiles.com\/#{directory_name}\/(.*)/
else
raise "#{self.class.name}#url_matcher was not implemented for the #{options[:provider]} provider"
end
end
|