Class: Shutterbug::Storage::S3Storage
- Inherits:
-
Object
- Object
- Shutterbug::Storage::S3Storage
- Defined in:
- lib/shutterbug/storage/s3_storage.rb
Instance Attribute Summary collapse
-
#filename ⇒ Object
Returns the value of attribute filename.
-
#stream_file ⇒ Object
Returns the value of attribute stream_file.
-
#url ⇒ Object
Returns the value of attribute url.
Class Method Summary collapse
- .connect! ⇒ Object
- .connection ⇒ Object
- .create_bin ⇒ Object
- .find(path) ⇒ Object
- .fs_path_exists?(long_path) ⇒ Boolean
- .handler_for(type) ⇒ Object
- .s3_bin ⇒ Object
- .write(name, filename) ⇒ Object
Instance Method Summary collapse
- #get_content ⇒ Object
-
#initialize(long_path, filetype) ⇒ S3Storage
constructor
A new instance of S3Storage.
- #redirect_s3 ⇒ Object
- #size ⇒ Object
Constructor Details
#initialize(long_path, filetype) ⇒ S3Storage
Returns a new instance of S3Storage.
54 55 56 57 58 59 |
# File 'lib/shutterbug/storage/s3_storage.rb', line 54 def initialize(long_path, filetype) @filename = File.basename(long_path) @source = long_path @stream_file = S3Storage.write(@filename, long_path) @url = @stream_file.public_url end |
Instance Attribute Details
#filename ⇒ Object
Returns the value of attribute filename.
6 7 8 |
# File 'lib/shutterbug/storage/s3_storage.rb', line 6 def filename @filename end |
#stream_file ⇒ Object
Returns the value of attribute stream_file.
8 9 10 |
# File 'lib/shutterbug/storage/s3_storage.rb', line 8 def stream_file @stream_file end |
#url ⇒ Object
Returns the value of attribute url.
7 8 9 |
# File 'lib/shutterbug/storage/s3_storage.rb', line 7 def url @url end |
Class Method Details
.connect! ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/shutterbug/storage/s3_storage.rb', line 10 def self.connect! Fog::Storage.new({ :provider => 'AWS', :aws_access_key_id => Configuration.instance.s3_key, :aws_secret_access_key => Configuration.instance.s3_secret }) end |
.connection ⇒ Object
18 19 20 |
# File 'lib/shutterbug/storage/s3_storage.rb', line 18 def self.connection @connection ||= self.connect! end |
.create_bin ⇒ Object
22 23 24 25 26 |
# File 'lib/shutterbug/storage/s3_storage.rb', line 22 def self.create_bin self.connection.directories.create( :key => Configuration.instance.s3_bin, :public => true) end |
.find(path) ⇒ Object
42 43 44 |
# File 'lib/shutterbug/storage/s3_storage.rb', line 42 def self.find(path) self.s3_bin.files.get(path) end |
.fs_path_exists?(long_path) ⇒ Boolean
46 47 48 |
# File 'lib/shutterbug/storage/s3_storage.rb', line 46 def self.fs_path_exists?(long_path) File.exists? long_path end |
.handler_for(type) ⇒ Object
50 51 52 |
# File 'lib/shutterbug/storage/s3_storage.rb', line 50 def self.handler_for(type) return self.handlers[type] end |
.s3_bin ⇒ Object
28 29 30 |
# File 'lib/shutterbug/storage/s3_storage.rb', line 28 def self.s3_bin @s3_bin ||= self.create_bin end |
.write(name, filename) ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/shutterbug/storage/s3_storage.rb', line 32 def self.write(name, filename) full_path = Configuration.instance.fs_path_for(filename) if self.fs_path_exists? full_path self.s3_bin.files.create( :key => name, :body => File.open(full_path), :public => true) end end |
Instance Method Details
#get_content ⇒ Object
61 62 63 |
# File 'lib/shutterbug/storage/s3_storage.rb', line 61 def get_content @stream_file.body end |
#redirect_s3 ⇒ Object
69 70 71 |
# File 'lib/shutterbug/storage/s3_storage.rb', line 69 def redirect_s3 return [301, {"Location" => self.url}, []] end |
#size ⇒ Object
65 66 67 |
# File 'lib/shutterbug/storage/s3_storage.rb', line 65 def size @stream_file.content_length end |