Class: CarrierWave::Storage::Couch::File
- Inherits:
-
Object
- Object
- CarrierWave::Storage::Couch::File
- Defined in:
- lib/carrierwave/storage/couch.rb
Instance Method Summary collapse
- #content_type ⇒ Object
- #content_type=(type) ⇒ Object
-
#delete ⇒ Object
Remove the file from Amazon S3.
-
#headers ⇒ Object
Headers returned from file retrieval.
-
#initialize(uploader, path) ⇒ File
constructor
A new instance of File.
-
#path ⇒ Object
Returns the current path of the file on S3.
-
#read ⇒ Object
Reads the contents of the file from S3.
- #size ⇒ Object
- #store(file) ⇒ Object
-
#url ⇒ Object
Returns the url on CouchDB.
Constructor Details
#initialize(uploader, path) ⇒ File
Returns a new instance of File.
39 40 41 42 |
# File 'lib/carrierwave/storage/couch.rb', line 39 def initialize(uploader, path) @uploader = uploader @path = path end |
Instance Method Details
#content_type ⇒ Object
91 92 93 |
# File 'lib/carrierwave/storage/couch.rb', line 91 def content_type headers["Content-Type"] end |
#content_type=(type) ⇒ Object
95 96 97 |
# File 'lib/carrierwave/storage/couch.rb', line 95 def content_type=(type) headers["Content-Type"] = type end |
#delete ⇒ Object
Remove the file from Amazon S3
71 72 73 |
# File 'lib/carrierwave/storage/couch.rb', line 71 def delete model.(@path) end |
#headers ⇒ Object
Headers returned from file retrieval
104 105 106 |
# File 'lib/carrierwave/storage/couch.rb', line 104 def headers @headers end |
#path ⇒ Object
Returns the current path of the file on S3
Returns
- String
-
A path
51 52 53 |
# File 'lib/carrierwave/storage/couch.rb', line 51 def path nil end |
#read ⇒ Object
Reads the contents of the file from S3
Returns
- String
-
contents of the file
62 63 64 65 66 |
# File 'lib/carrierwave/storage/couch.rb', line 62 def read result = model.(@path) @headers = result.headers result.body end |
#size ⇒ Object
99 100 101 |
# File 'lib/carrierwave/storage/couch.rb', line 99 def size headers['Content-Length'].to_i end |
#store(file) ⇒ Object
86 87 88 89 |
# File 'lib/carrierwave/storage/couch.rb', line 86 def store(file) content_type ||= file.content_type # this might cause problems if content type changes between read and upload (unlikely) model.(file.filename, file.read, {:content_type => content_type}) end |
#url ⇒ Object
Returns the url on CouchDB
Returns
- String
-
content’s url
82 83 84 |
# File 'lib/carrierwave/storage/couch.rb', line 82 def url @uploader.couch_connection + "/" + @uploader.couch_database + "/" + model.id + "/" + @path end |