Class: CarrierWave::Storage::Riak::File
- Inherits:
-
Object
- Object
- CarrierWave::Storage::Riak::File
- Defined in:
- lib/carrierwave/storage/riak.rb
Instance Method Summary collapse
-
#content_type ⇒ Object
Lookup value for file content-type header.
-
#content_type=(new_content_type) ⇒ Object
Set non-default content-type header (default is file.content_type).
-
#delete ⇒ Object
Remove the file from Riak.
-
#initialize(uploader, base, bucket, key) ⇒ File
constructor
A new instance of File.
-
#key ⇒ Object
Returns the key of the riak file.
-
#meta ⇒ Object
Return riak meta data.
-
#path ⇒ Object
Returns the path of the riak file.
-
#read ⇒ Object
Reads the contents of the file from Riak.
-
#size ⇒ Object
Return size of file body.
-
#store(file) ⇒ Object
Writes the supplied data into Riak.
Constructor Details
#initialize(uploader, base, bucket, key) ⇒ File
Returns a new instance of File.
52 53 54 55 56 57 |
# File 'lib/carrierwave/storage/riak.rb', line 52 def initialize(uploader, base, bucket, key) @uploader = uploader @bucket = bucket @key = key @base = base end |
Instance Method Details
#content_type ⇒ Object
Lookup value for file content-type header
Returns
- String
-
value of content-type
88 89 90 |
# File 'lib/carrierwave/storage/riak.rb', line 88 def content_type @content_type || file.content_type end |
#content_type=(new_content_type) ⇒ Object
Set non-default content-type header (default is file.content_type)
Returns
- String
-
returns new content type value
99 100 101 |
# File 'lib/carrierwave/storage/riak.rb', line 99 def content_type=(new_content_type) @content_type = new_content_type end |
#delete ⇒ Object
Remove the file from Riak
139 140 141 142 143 144 145 146 147 |
# File 'lib/carrierwave/storage/riak.rb', line 139 def delete begin riak_client.delete(@bucket, @key) true rescue Exception => e # If the file's not there, don't panic nil end end |
#key ⇒ Object
Returns the key of the riak file
Returns
- String
-
A filename
66 67 68 |
# File 'lib/carrierwave/storage/riak.rb', line 66 def key @key end |
#meta ⇒ Object
Return riak meta data
Returns
- Haash
-
A hash of X-Riak-Meta-* headers
110 111 112 |
# File 'lib/carrierwave/storage/riak.rb', line 110 def file. end |
#path ⇒ Object
Returns the path of the riak file
Returns
- String
-
A full path to file
77 78 79 |
# File 'lib/carrierwave/storage/riak.rb', line 77 def path Pathname.new('/').join(@bucket).join(key).to_s end |
#read ⇒ Object
Reads the contents of the file from Riak
Returns
- String
-
contents of the file
132 133 134 |
# File 'lib/carrierwave/storage/riak.rb', line 132 def read file.raw_data end |
#size ⇒ Object
Return size of file body
Returns
- Integer
-
size of file body
121 122 123 |
# File 'lib/carrierwave/storage/riak.rb', line 121 def size file.raw_data.length end |
#store(file) ⇒ Object
Writes the supplied data into Riak
Returns
boolean
156 157 158 159 160 161 |
# File 'lib/carrierwave/storage/riak.rb', line 156 def store(file) @file = riak_client.store(@bucket, @key, file.read, {:content_type => file.content_type}) @key = @file.key @uploader.key = @key true end |