Class: CarrierWave::Storage::Couch::File

Inherits:
Object
  • Object
show all
Defined in:
lib/carrierwave/storage/couch.rb

Instance Method Summary collapse

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_typeObject



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

#deleteObject

Remove the file from Amazon S3



71
72
73
# File 'lib/carrierwave/storage/couch.rb', line 71

def delete
  model.delete_attachment(@path)
end

#headersObject

Headers returned from file retrieval



104
105
106
# File 'lib/carrierwave/storage/couch.rb', line 104

def headers
  @headers
end

#pathObject

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

#readObject

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.fetch_attachment(@path)
  @headers = result.headers
  result.body
end

#sizeObject



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.put_attachment(file.filename, file.read, {:content_type => content_type})
end

#urlObject

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